Amazon Gift Cards

Tuesday, April 20, 2010

Change View Position in Android

After a long silence, im back with a new Android post, a problem i encounter recently. So you have a view, you want to change the location of the view how can you do that?

There are a lot of ways in dealing with this, you could use SurfaceView and add some Views on top of it, or if you think its hard to deal with SurfaceView then here is a solution.

This solution might not be the best solution but it does work, and it works if you if still need to cater the first batch of android phones that comes with 1.5,1.6.

yourView.layout(left,top,left+width (right), top+height(bottom)

I used in a custom view with animation where setFillAfter is not working properly, so i have to come out with a solution on where the last frame of the animation is the layout(l,t,r,b) new position.

1 comment:

ShadowMare said...

Thank you for this hint!

I have the same problem with a TranslateAnimation. FillAfter keeps the view where it should be, but it does not react to click events in the new area and the layout which it is in is not expanding properly.
So I'm trying to set it's new position manually but I can't get it to work.

Can you tell me how you solved your similar problem?
Thank you!