标签:
drawable
目录下新建一个xml
文件,内容如下:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" > //onshot是指定是否循环播放 <item android:drawable="@drawable/desktop_rocket_launch_1" //Frame动画的图片 android:duration="50"/> //播放这个图片持续的时间 <item android:drawable="@drawable/desktop_rocket_launch_2" android:duration="100"/> </animation-list>
AnimationDrawable rocketAnimation; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView rocketImage = (ImageView) findViewById(R.id.iv); rocketImage.setBackgroundResource(R.drawable.animlist); //将上边建的Frame动画的xml文件通过背景资源设置给图片 rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); //获取到图片的背景资源 } public void start(View view) { if (!rocketAnimation.isRunning()) { rocketAnimation.start(); //播放 }
}
标签:
原文地址:http://www.cnblogs.com/huangzx/p/4484366.html