WRAP_CONTENT not working after dynamically adding views

后端 未结 8 885
借酒劲吻你
借酒劲吻你 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

    You are getting this problem because you set your layout first and then add its content dynamically.

    You are telling the layout to wrap to the content that is not yet their. Try using your layout inflater after you have grabbed your content

    0 讨论(0)
  • 2020-12-05 02:56

    Try calling requestLayout on the children.

    I recently had a similar problem and was similarly frustrated that things like invalidate and requestLayout seemed to do nothing. What I didn't understand is that requestLayout doesn't propagate down to its children; it propagates up to its parents. To re-measure something that was previously measured, I had to call requestLayout on the View that changed rather than the View I actually wanted to resize.

    0 讨论(0)
提交回复
热议问题