随笔 - 91,  文章 - 0,  评论 - 1,  阅读 - 87621

 

  • 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   道无涯  阅读(230)  评论(0编辑  收藏  举报
努力加载评论中...

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示