TranslateAnimation

TranslateAnimation是平移动画。

1.1、Java表示

TranslateAnimation有三个构造方法:

public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

示例:

TextView textView = (TextView) findViewById(R.id.text_view);

TranslateAnimation translateAnimation = new TranslateAnimation(0, 100, 0, 100);
translateAnimation.setDuration(2000);
translateAnimation.setFillAfter(true);
translateAnimation.setInterpolator(new LinearInterpolator());
textView.startAnimation(translateAnimation);
1.2、XML表示

res/anim目录中存放的xml文件,以translate作为根元素。

public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)