TranslateAnimation 位移动画效果
2015-08-05 20:16
351 查看
TranslateAnimation比较常用,比如QQ,网易新闻菜单条的动画,就可以用TranslateAnimation实现,
通过TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 来定义动画
参数说明:
常用方法:
Xml属性:
代码:
通过TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 来定义动画
参数说明:
float fromXDelta 动画开始的点离当前View X坐标上的差值 float toXDelta 动画结束的点离当前View X坐标上的差值 float fromYDelta 动画开始的点离当前View Y坐标上的差值 float toYDelta 动画开始的点离当前View Y坐标上的差值
常用方法:
animation.setDuration(long durationMillis);//设置动画持续时间 animation.setRepeatCount(int i);//设置重复次数 animation.setRepeatMode(Animation.REVERSE);//设置反方向执行
Xml属性:
android:duration:运行动画的时间 android:repeatCount:定义动画重复的时间
代码:
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); /** 设置位移动画 向右位移150 */ final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0); animation.setDuration(2000);//设置动画持续时间 animation.setRepeatCount(2);//设置重复次数 animation.setRepeatMode(Animation.REVERSE);//设置反方向执行 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(); } }); } }
相关文章推荐
- 南阳 oj 郁闷的c小加(三) 题目409
- Longest Common Prefix
- 杭电 2015 偶数求和
- zedboard中断实现
- iOS 使用nib文件(二)
- hdoj 1728 逃离迷宫 【BFS 记录转弯次数】
- 【C】字符串的输入,求输入字符串中最长的单词
- linux使用普通账户时,无法登录,提示“-bash: fork: retry: Resource temporarily unavailable”
- Java大数 字符串处理 HDU2100
- zoj1003Crashing Balloon
- IOS学习之Objective-C中的@property和@synthesize用法
- 最长回文自负串1 求长度
- UIScrolView里自己滚动滑动 ,无限制那种
- day16
- Hudson任务配置说明
- 二叉树左旋和右旋
- 揭秘网络女主播:百万年薪下的暗黑成长史(全)
- 数据结构 表达式求值
- 多线程处理mysql数据
- zedboard中断main