问题描述:
为ImageView定义渐变动画。
解决方法:
1.为ImageView设置一个BackGround或者ImageDrawable。
2.通过ImageView的setAnimation()方法开始动画。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 定义一个ImageView用来显示动画
ImageView img = new ImageView(this);
// 设置ImageView背景
img.setBackgroundResource(R.drawable.ic_launcher);
setContentView(img);
// 定义alpha动画
AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
alpha.setDuration(2000);
// 将动画设置到ImageView上
img.setAnimation(alpha);
}