TransitionDrawable

  • 1.首先创建一个xmldrawable 目录下

transition_image

1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/first" />
<item android:drawable="@drawable/two" />
</transition>
  • 2.在xml中引用
1
android:drawable="@drawable/transition_image"
  • 3.在Activity中使用
1
2
3
ImageView mImageView = (ImageView) findViewById(R.id.iv); 
TransitionDrawable transitionDrawable = (TransitionDrawable) mImageView.getDrawable();
transitionDrawable.startTransition(3000)

另外一种写法实现多张图片效果

1
2
3
TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[]{getResources().getDrawable(R.drawable.first),getResources().getDrawable(R.drawable.two)});
mImageView.setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(3000);
-------------本文结束感谢您的阅读-------------