android-Frame Animation

Source: Internet
Author: User

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

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.