码迷,mamicode.com
首页 > 其他好文 > 详细

测试drawable animation

时间:2018-07-24 23:47:48      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:span   star   near   idt   line   aac   android   button   ==   

 

public class DAActivity extends Activity implements OnClickListener {

    private ImageView iv_da_mm;
    private Button btn_da_start;
    private Button btn_da_stop;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_da);
        iv_da_mm = (ImageView) findViewById(R.id.iv_da_mm);
        btn_da_start = (Button) findViewById(R.id.btn_da_start);
        btn_da_stop = (Button) findViewById(R.id.btn_da_stop);

        btn_da_start.setOnClickListener(this);
        btn_da_stop.setOnClickListener(this);
    }

    private AnimationDrawable animationDrawable;
    @Override
    public void onClick(View v) {
        if (v == btn_da_start) {
            if(animationDrawable==null) {
                //得到背景动画图片对象
                animationDrawable = (AnimationDrawable) iv_da_mm.getBackground();
                //启动
                animationDrawable.start();
            }
            
        } else if (v == btn_da_stop) {
            if(animationDrawable!=null) {
                animationDrawable.stop();
                animationDrawable = null;
            }
        }
    }
}

技术分享图片


drawable_animation_test.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/nv1" android:duration="500"/> <item android:drawable="@drawable/nv2" android:duration="500"/> <item android:drawable="@drawable/nv3" android:duration="500"/> <item android:drawable="@drawable/nv4" android:duration="500"> </item> </animation-list>

activity_animation_da.xml

<?
xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/iv_da_mm" android:layout_width="80dp" android:layout_height="80dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="160dp" android:background="@drawable/drawable_animation_test"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" > <Button android:id="@+id/btn_da_start" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="启动动画" /> <Button android:id="@+id/btn_da_stop" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="结束动画" /> </LinearLayout> </RelativeLayout>

 

测试drawable animation

标签:span   star   near   idt   line   aac   android   button   ==   

原文地址:https://www.cnblogs.com/znsongshu/p/9363219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!