android view動畫問題
阿新 • • 發佈:2019-01-26
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 }
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
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
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
26 }