/res/drawable/flag.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list     
    xmlns:andro
    >
<!--android:duration="xxx"控制该图片显示时间长度-->
    <item android:drawable="@drawable/f03" android:duration="100" />
    <item android:drawable="@drawable/f04" android:duration="100" />
    <item android:drawable="@drawable/f05" android:duration="100" />
    <item android:drawable="@drawable/f06" android:duration="100" />
    <item android:drawable="@drawable/f07" android:duration="100" />
    <item android:drawable="@drawable/f08" android:duration="100" />
    <item android:drawable="@drawable/f09" android:duration="100" />
    <item android:drawable="@drawable/f10" android:duration="100" />    
</animation-list>

/res/layout/splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:andro        
        >
     -->
</LinearLayout>

MainActivity.java

final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
        splashImageView.setBackgroundResource(R.drawable.flag);
        final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
        splashImageView.post(new Runnable(){
            @Override
            public void run() {
                frameAnimation.start();//启动动画
            // frameAnimation.stop(); //关闭动画
            }            
        });
 

除此之外:在AnimationDrawable中,我们还可以看到如下的几个重要方法:

setOneShot(boolean flag) 和在配置文件中进行配置一样,可以设置动画是否播放一次,false为连续播放;

addFrame (Drawable frame, int duration) 动态的添加一个图片进入该动画中

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-09-09
  • 2021-11-22
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2021-08-15
  • 2022-02-09
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案