Change Relative layout width and height dynamically

后端 未结 7 1154
眼角桃花
眼角桃花 2020-12-14 09:30

Hi i am using following layout structure inside LinearLayout



        
7条回答
  •  遥遥无期
    2020-12-14 09:51

    Android does NOT refresh layout of views with wrap_content once it has been displayed. Even with invalidate() or requestLayout(). So if you add a child view, or modify the content dynamically, you're screwed.

    getLayoutParams().height = x plus requestLayout() are a good solution if you know the "x", and if you need to do it ONLY ONCE. After that the wrap_content in LayoutParams is lost, since you have overridden it.

    To solve that, I've written a static class that recomputes the sizes and forces the update of the layout for the views with wrap_content. The code and instructions to use are available here:

    https://github.com/ea167/android-layout-wrap-content-updater

    Enjoy!

提交回复
热议问题