Android 动画之AlphaAnimation应用详解
Android 动画之AlphaAnimation应用详解
发布时间:2016-12-28 来源:查字典编辑
摘要:android中提供了4中动画:AlphaAnimation透明度动画效果ScaleAnimation缩放动画效果TranslateAnim...

android中提供了4中动画:

AlphaAnimation 透明度动画效果

ScaleAnimation 缩放动画效果

TranslateAnimation 位移动画效果

RotateAnimation 旋转动画效果

本节讲解AlphaAnimation 动画,窗口的动画效果,淡入淡出什么的,有些游戏的欢迎动画,logo的淡入淡出效果就使用AlphaAnimation。

直接看代码:

复制代码 代码如下:

public class MainActivity extends Activity {

ImageView image;

Button start;

Button cancel;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

image = (ImageView) findViewById(R.id.main_img);

start = (Button) findViewById(R.id.main_start);

cancel = (Button) findViewById(R.id.main_cancel);

/** 设置透明度渐变动画 */

final AlphaAnimation animation = new AlphaAnimation(1, 0);

animation.setDuration(2000);//设置动画持续时间

/** 常用方法 */

//animation.setRepeatCount(int repeatCount);//设置重复次数

//animation.setFillAfter(boolean);//动画执行完后是否停留在执行完的状态

//animation.setStartOffset(long startOffset);//执行前的等待时间

start.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {

image.setAnimation(animation);

/** 开始动画 */

animation.startNow();

}

});

cancel.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

/** 结束动画 */

animation.cancel();

}

});

}

}<SPAN><SPAN>

</SPAN></SPAN>

效果:

Android 动画之AlphaAnimation应用详解1

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新安卓软件开发学习
热门安卓软件开发学习
编程开发子分类