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

    本节讲解TranslateAnimation动画,TranslateAnimation比较常用,比如QQ,网易新闻菜单条的动画,就可以用TranslateAnimation实现,本文将详细介绍通过TranslateAnimation 来定义动画,需要的朋友可以参考下

    android中提供了4中动画: 

    AlphaAnimation 透明度动画效果 
    ScaleAnimation 缩放动画效果 
    TranslateAnimation 位移动画效果 
    RotateAnimation 旋转动画效果 

    参数说明: 

    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(); 
    } 
    }); 
    } 
    } 

    连接如下:

    AlphaAnimation 透明度动画效果 
    ScaleAnimation 缩放动画效果 
    TranslateAnimation 位移动画效果 
    RotateAnimation 旋转动画效果 

  • 相关阅读:
    rt_list_entry() 函数
    替换空格
    跳台阶
    斐波那契数列
    基于5221码的同步十进制加法计数器
    强连通分量+Tarjia+缩点
    次小生成树
    差分约束
    P1547 Out of Hay
    P1197 [JSOI2008]星球大战
  • 原文地址:https://www.cnblogs.com/stuart/p/4469142.html
Copyright © 2011-2022 走看看