zoukankan      html  css  js  c++  java
  • Android 动画之TranslateAnimation应用详解

    TranslateAnimation比较常用,比如QQ,网易新闻菜单条的动画,就可以用TranslateAnimation实现,
    通过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);//设置反方向执行 

    代码:

     
    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(); 
    } 
    }); 
    } 
    } 
  • 相关阅读:
    Jquery的事件与动画-----下雨的天气好凉爽
    JQuery选择器--------没有它就没有页面效果
    JavaScript对象--------------你又知道那些
    实体类----app-config
    知错就改,善莫大焉!!!
    二分查找模板
    《软件工程》学习资料积累
    《计算机算法设计与分析》的学习资源和好的课程积累
    软件的概念
    递归方程的求解和算法时间复杂度的分析
  • 原文地址:https://www.cnblogs.com/AceIsSunshineRain/p/5188988.html
Copyright © 2011-2022 走看看