Alex Rivera | Logout

Android - Animate a View's topMargin/bottomMargin/etc in LinearLayout or RelativeLayout

Asked 2010-02-10T18:45:15.303
11

I am trying to create a menu that slides up from the bottom. It starts with the menu's view just visible at the bottom of the screen, and then clicking it causes it to slide up. I tried using a TranslateAnimation, but although the pixels move, the hit areas of the menu are in the same position as before. So I think that if I can adjust the menu's margins after the animation is complete, this will accomplish what I want. However, I can't figure out how to adjust the margins.

I've tried to create a LinearLayout.LayoutMargins object and then set its margins and apply it to the menu's view (which is a LinearLayout), but this doesn't work.

Any ideas?

Edit
Report

1 Answer

1

This post helped me get my animation working. In my case, I have a full screen webview. On some user action, this webview slides to the right, about 70% and a new webview emerges from the left and takes the available space. End result, a new webview covers the 70% (x-axis) and the old webview the rest. Arne's solution helped me immensely, setting up the margin to the old view as soon as the animation is done. Pseudo code:

       marginParams.leftMargin = 336; //(70% of 480px)

But I faced a weird behavior, I guess my old webview (which now only occupies 30% space), was reformatting its contents, may be thinking that it is now squeezed into a smaller space, rather than behaving as if its just slid to the right. In other words, as soon as I set this margin, the html layout of the webview changed. Again, I had no idea why and my guess is it thought its parent window size changed. Based on that assumption, I added one more line of code:

      marginParams.rightMargin = -336; //(same amount, but negative margin!)

And that did the trick, no reformatting of the html contents and I can interact with both webviews in parallel.

I am posting this as a big Thank you to Arne for the idea and also to get any inputs for the behavior I saw and my assumptions for it. I actually like the end solution, makes logical sense, but I may be wrong . . . any thoughts and input would be greatly appreciated. Thank you very much.

answered 2012-06-12T17:41:34.763

Your Answer