android-Frame Animation
One-frame animation
Also called Drawable Animation, is the transition between different objects faster formation of the animation, but also the principle of animation
gave not much to say, see demo
The following example is to achieve 4 pictures of the transition animation effect, relatively simple
1, define XML for 4 images in drawable and transition time
<?xml version= "1.0" encoding= "Utf-8"?><animation-list xmlns:android="Http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable= "@drawable/gesture1" android:duration="200 "></Item> <item android:drawable="@drawable/gesture2" android:duration= ">"</Item> <item android:drawable= "@drawable/gesture3" android:duration="200 "></Item></animation-list>
2. Define layout layouts for displaying pictures
<?xml version= "1.0" encoding= "Utf-8"?><linearlayout xmlns:android="Http://schemas.android.com/apk/res/android" Android:layout_width="Match_parent"android:layout_height="Match_parent" Android:orientation="vertical" > <ImageViewandroid:id="@+id/imageview"android:layout_width= "Wrap_content" android:layout_height="wrap_content" /> <buttonandroid:id= "@+id/buttonanimlist"android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "android:text=" OK " / > </linearlayout>
3, defining the main activity class
Public class myanimationlistactivity extends Activity{ PrivateAnimationdrawable manimationdrawable;@Override protected void onCreate(Bundle savedinstancestate) {//TODO auto-generated method stub Super. OnCreate (Savedinstancestate);//Set layout fileSetcontentview (r.layout.my_animlist_layout);//Get the layout of the ImageView objectImageView _imageview = (ImageView) Findviewbyid (R.id.imageview);//Get the background of ImageView_imageview.setbackgroundresource (r.drawable.my_anim_list);//Use Animationdrawable to complete frame animationManimationdrawable = (animationdrawable) _imageview.getbackground ();//Get button ObjectButton _buttonlist = (button) Findviewbyid (r.id.buttonanimlist);//Set Click events_buttonlist.setonclicklistener (NewOnclicklistener () {@Override Public void OnClick(View arg0) {//TODO auto-generated method stub //Animation plays only once, set to TrueManimationdrawable.setoneshot (true);//Animation startManimationdrawable.start (); } }); }}
Run the program, click the button, the pictures switch to each other and play only once
Copyright NOTICE: Welcome to communicate the error of the article, must humbly accept, QQ872785786
android-Frame Animation