Android App--imitation American loading loading animation

Source: Internet
Author: User

Objective

Must have used the United States Group client user to the American regiment that loaded villain animation impression is very deep, a cute villain in that desperately run. This animation implementation of the method is actually a lot, today here with frame animation to achieve.


One



Second, the layout file

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:paddingbottom= "@dimen/activity_vertical_margin"    android:paddingleft= "@dimen/activity_ Horizontal_margin "    android:paddingright=" @dimen/activity_horizontal_margin "    android:paddingtop=" @dimen /activity_vertical_margin "    tools:context=". Mainactivity ">    <imageview        android:id=" @+id/imageview "        android:layout_width=" Fill_parent "        android:layout_height= "fill_parent"        android:onclick= "Start"        android:scaletype= "Fitcenter"        android:src= "@anim/frame"/></relativelayout>

Create a new Anim file, which is stored in the picture to prepare frame animation, the picture can be directly to the United States Regiment of the installation package to be extracted.

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:oneshot=" false ">    <item android:drawable=" @drawable/progress_loading_image_01 " android:duration= "/>    <item android:drawable=" @drawable/progress_loading_image_02 "android:duration= "/></animation-list>"

Main function Code:

Using the Getdrawabel method of image view to get a Animationdrawable object and then call the Start method to start the animation.

public class Mainactivity extends Activity {private ImageView imageview;private animationdrawable ad; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); ImageView = (ImageView) Findviewbyid (r.id.imageview); ad = (animationdrawable) imageview.getdrawable ();//Get Picture content , strongly converted to animated object}public void Start (View v) {if (ad.isrunning ()) ad.stop (); Ad.start ();//Start Playback}}




Android App--imitation American loading loading animation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.