1 public void slideview(
final float p1,
final float p2) {
2 TranslateAnimation animation =
new TranslateAnimation(p1, p2, 0, 0);
3 animation.setInterpolator(
new OvershootInterpolator());
4 animation.setDuration(durationMillis);
5 animation.setStartOffset(delayMillis);
6 animation.setAnimationListener(
new Animation.AnimationListener() {
7 @Override
8 public void onAnimationStart(Animation animation) {
9 }
10
11 @Override
12 public void onAnimationRepeat(Animation animation) {
13 }
14
15 @Override
16 public void onAnimationEnd(Animation animation) {
17 int left = view.getLeft()+(
int)(p2-p1);
18 int top = view.getTop();
19 int width = view.getWidth();
20 int height = view.getHeight();
21 view.clearAnimation();
22 view.layout(left, top, left+width, top+height);
23 }
24 });
25 view.startAnimation(animation);
26 }
经过查资料得知,animation.setFillAfter(true); 只是将view移动到了目标位置,但是view绑定的点击事件还在原来位置,导致点击时会先闪一下
1 animation.setAnimationListener(
new Animation.AnimationListener() {
2 @Override
3 public void onAnimationStart(Animation animation) {
4 }
5
6 @Override
7 public void onAnimationRepeat(Animation animation) {
8 }
9
10 @Override
11 public void onAnimationEnd(Animation animation) {
12 int left = view.getLeft()+(
int)(p2-p1);
13 int top = view.getTop();
14 int width = view.getWidth();
15 int height = view.getHeight();
16 view.clearAnimation();
17 view.layout(left, top, left+width, top+height);
18 }
19 });