Use frame motion in Android

Source: Internet
Author: User

frame animation: refers to a number of pictures quickly switch

Let's look at the effect of the implementation



Implementation method

Step one: Create an Android project using Android Studio, and add a picture of each frame used to create frame animations in the Drawable folder


Step Two: Create a new Frameanimation.xml file under the Drawable folder and add the following code in Frameannimation.xml

<?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/g1 "android:duration=" $ "/> <ite M android:drawable= "@drawable/g2" android:duration= "/> <item android:drawable=" @drawable/g3 "Android: duration= "/> <item android:drawable=" @drawable/g4 "android:duration=" $ "/> <item android:drawable = "@drawable/g5" android:duration= "/> <item android:drawable=" @drawable/g6 "android:duration="/> " Lt;item android:drawable= "@drawable/g7" android:duration= "$"/> <item android:drawable= "@drawable/g8" android:duration= "/> <item android:drawable=" @drawable/g9 "android:duration="/> <item android: drawable= "@drawable/g10" android:duration= "/> <item android:drawable=" @drawable/g11 "android:duration=" "/></animation-list>


Step Three:Modify the Activity_main.xml file
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout 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"    tools:context= "com.fyt.frameanimation.MainActivity"    android:o rientation= "vertical" >    <imageview        android:id= "@+id/iv"        android:layout_width= "Wrap_content"        android:layout_height= "Wrap_content"/></linearlayout>

Last step: Modify the Mainactivity.java file

Package Com.fyt.frameanimation;import Android.app.activity;import android.graphics.drawable.AnimationDrawable; Import Android.os.bundle;import Android.widget.imageview;public class Mainactivity extends Activity {    @Override    protected void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main);        Get the ImageView control on the layout file        ImageView IV = (ImageView) Findviewbyid (R.ID.IV);        The resource file of the frame animation is specified as the background        Iv.setbackgroundresource (r.drawable.frameanimation) of the ImageView;        Gets the background of the ImageView        animationdrawable ad = (animationdrawable) iv.getbackground ();        Play frame animation        Ad.start ();}    }

Use frame motion in Android

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.