Interpolator的用法 Android Animation

Animation3:

主要是Interpolator的用法。public void setInterpolator (Interpolator i)Sets the acceleration curve for this animation. Defaults to a linear interpolation(设置动画的加速度效果)



首先在第一个TextView中加入动画效果:

1:  final View target = findViewById(R.id.target);//TextView

2:  final View targetParent = (View) target.getParent();//TextView的父view

3: 

4:  Animation a = new TranslateAnimation(0.0f, targetParent.getWidth()//设置位移动画

5:      - target.getWidth() - targetParent.getPaddingLeft()

6:      - targetParent.getPaddingRight(), 0.0f, 0.0f);

7:  a.setDuration(1000);//持续1秒

8:  a.setStartOffset(300);

9:  a.setRepeatMode(Animation.RESTART);//重复

10:  a.setRepeatCount(Animation.INFINITE);//无限次
android自带的7种Interpolator 效果

1:  switch (position) {

2:          case 0:

3:              a.setInterpolator(AnimationUtils.loadInterpolator(this,

4:                  android.R.anim.accelerate_interpolator));

5:              break;

6:          case 1:

7:              a.setInterpolator(AnimationUtils.loadInterpolator(this,

8:                  android.R.anim.decelerate_interpolator));

9:              break;

10:          case 2;

11:              a.setInterpolator(AnimationUtils.loadInterpolator(this,

12:                  android.R.anim.accelerate_decelerate_interpolator));

13:              break;

14:          case 3:

15:              a.setInterpolator(AnimationUtils.loadInterpolator(this,

16:                  android.R.anim.anticipate_interpolator));

17:              break;

18:          case 4:

19:              a.setInterpolator(AnimationUtils.loadInterpolator(this,

20:                  android.R.anim.overshoot_interpolator));

21:              break;

22:          case 5:

23:              a.setInterpolator(AnimationUtils.loadInterpolator(this,

24:                  android.R.anim.anticipate_overshoot_interpolator));

25:              break;

26:          case 6:

27:              a.setInterpolator(AnimationUtils.loadInterpolator(this,

28:                  android.R.anim.bounce_interpolator));

29:              break;

30:          }

32:          target.startAnimation(a);

转载:http://hi.baidu.com/luyanlong1/blog/item/c0e8d7a99dab6bdf7dd92a0b.html

你可能感兴趣的:(interpolator)