WRAP_CONTENT not working after dynamically adding views

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

    A simple way to update the size of a View with WRAP_CONTENT is change the visibility to GONE and back to the old visibility.

    int visibility = view.getVisibility();
    view.setVisibility(View.GONE);
    view.setVisibility(visibility);
    

    TESTED ON ANDROID JELLY BEAN IN 2014

    MAY NOT WORK ON NEWER ANDROID VERSIONS

提交回复
热议问题