Android - How to interact with a view after it has

2019-04-02 07:29发布

问题:

I have a view that is animated using TranslateAnimation:

TranslateAnimation translateAnim = new TranslateAnimation(fromX, toX, fromY, toY);
translateAnim.setDuration(SLIDING_SPEED);
translateAnim.setInterpolator(new BounceInterpolator());
translateAnim.setFillAfter(true);
mSlidingView.startAnimation(translateAnim);

The animation works fine but after it's finished I can't click on the view anymore. Instead I can still click on its previous location.

I have searched for similar questions (here, here and here) on StackOverflow but none of them provides any solution. I have heard that the ObjectAnimator fixed this, but is there anything I can do using the previous API? (I don't want to rely on yet another third party library like NineOldAndroids to support the new animation API on pre-honeycomb devices). Oh and I have tried to invalidate the view but it doesn't change anything.

Any idea?

Thanks!

回答1:

Well, I guess there is not link, but have you tried : (before setFillAfter)

translateAnim.setFillEnabled(true);


回答2:

In API 11+, We can do that by ObjectAnimator class.

In API 10-, When we translate a view, the visual view will be translated, but the physical location still in the old location, changing the margin of the translated view after finish the animation could solve the problem.