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

后端 未结 5 2151
被撕碎了的回忆
被撕碎了的回忆 2020-12-25 08:24

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 sli

5条回答
  •  旧时难觅i
    2020-12-25 08:57

    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.

提交回复
热议问题