WRAP_CONTENT not working after dynamically adding views

后端 未结 8 928
借酒劲吻你
借酒劲吻你 2020-12-05 02:28

I\'m trying to create a fragment that lays out a series of custom views dynamically. The main content for this layout is a RelativeLayout nested in a LinearLayout (to center

8条回答
  •  甜味超标
    2020-12-05 02:48

    Android does NOT refresh layout of views with "wrap_content" once it has been displayed.

    So if you add a child view, or modify the content dynamically, you're screwed. I do agree that this is a nightmare and a real flaw in Android UI!

    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!

提交回复
热议问题