Move view itself to animation's end position

2019-07-29 03:54发布

问题:

I'm having a real serious problem. I want to implement UI where some view is moving on the screen and the user can touch it. I know that regular API-1 Animation framework move just the graphics of the view, and API-11 Animator framework move the view itself, but the problem is that it support only API-11+ which is very high.

I thought that instead of putting click listener on the view itself - I will identify which item was clicked by getting its position. So this is what I will do: * User touch the screen. * Stop all the animations. * Get all the animated views to the position where the animation was ended. (This is were I need your help). * Iterate over the views and find out if the click was in the area of one of them.

But I can't find a way to move the view to the animation's end position.

If someone knows a way, I will be very thankful!

Thanks in advance, Elad

回答1:

But I can't find a way to move the view to the animation's end position.

Modify its LayoutParams to move it to the end position. Use getLayoutParams() on the View, cast it to the appropriate type based on its container, modify the LayoutParams object, then call setLayoutParams() on the View to commit the changes.