当前位置: 移动技术网 > 移动技术>移动开发>Android > Android 动画之AlphaAnimation应用详解

Android 动画之AlphaAnimation应用详解

2019年07月24日  | 移动技术网移动技术  | 我要评论
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 style="color: #333333; font-family: microsoft yahei"><span style="font-size: 14px; line-height: 26px">
</span></span>

效果:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网