Android两张图片渐变实现
下面代码实现从bg1.png到bg2.png经过4000ms的转变。主要用到了android.graphics.drawable.TransitionDrawable.TransitionDrawable类
//得到此View下的资源
Resource res = getResource();
//图片渐变对象
TransitionDrawable imageTransitionDrawable = null;
imageTransitionDrawable = new TransitionDrawable(
new Drawable[]{
res.getDrawable(R.drawable.bg1),
res.getDrawable(R.drawable.bg2)
}
);
//设置背景图片为渐变图片
this.setBackgroundDrawable(imageTransitionDrawable);
//经过4000ms的图片渐变过程
imageTransitionDrawable.startTransition(4000);
本文介绍了一种在Android中实现两张图片渐变的方法。通过使用TransitionDrawable类,可以在指定的时间内完成从一张图片到另一张图片的平滑过渡。
2671

被折叠的 条评论
为什么被折叠?



