Skip to content Skip to sidebar Skip to footer

How To Properly Move A View?

Can someone please explain to a noob the correct way to animate a View so its touch area and image actually move together?! I have read lots of posts and questions and tutorials, b

Solution 1:

What you have is basically fine, with two flaws:

  1. You are using setFillAfter(), which is not especially useful

  2. You are calling layout() and setRight() and stuff, which is not especially effective

Instead, in onAnimationEnd(), you need to modify the LayoutParams of the View to reflect the new position you want the widget to be in. The size and position of a widget is dictated by the layout rules it negotiates with its container. Initially, those are set via your layout XML resource. By modifying the LayoutParams at runtime, you are changing what those rules are.

What those LayoutParams are (LinearLayout.LayoutParams, RelativeLayout.LayoutParams, etc.) and what values you should specify in them, we cannot tell you, because we don't know what you are doing.

Post a Comment for "How To Properly Move A View?"