android 多张图片动画方式轮播(转载)
16lz
2022-05-28
android 图片轮播动画
/res/drawable/flag.xml
<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flaganim"
android:oneshot="false"
>
/res/layout/splash.xml
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TheSplashLayout"
android:layout_gravity="center"
>
android:layout_height="wrap_content"
android:id="@+id/SplashImageView"
android:layout_gravity="center"
>
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) 动态的添加一个图片进入该动画中
转载于:https://www.cnblogs.com/xubuhang/p/4223502.html
更多相关文章
- Android绘制圆形图片(五)
- Android通过内容提供器获取相册中所有图片
- Android(安卓)属性动画中心点无限循环
- Android(安卓)改变ImageView图片的Bitmap大小
- 一个Android实现图片的倒影效果的代码示例
- Android(安卓)读取Assets中图片
- android 按比例缩放图片(适屏)
- android 文字或者图片生成.pdf文件
- Android(安卓)二级动画弹出菜单