• 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>

     

  • 播放Frame动画
       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();  //播放
             }
    }

     

posted on 2015-05-07 11:39  道无涯  阅读(229)  评论(0编辑  收藏  举报