Why does a LinearLayout which is invisible take up space?

后端 未结 4 802
心在旅途
心在旅途 2021-02-05 09:10

I\'ve got the following LinearLayout...



        
相关标签:
4条回答
  • 2021-02-05 09:29

    Because you have to set the visibility to gone if you want that the view takes no space.

    0 讨论(0)
  • 2021-02-05 09:34

    Change invisible by gone that will do the trick.

    public static final int View.INVISIBLE

    This view is invisible, but it still takes up space for layout purposes. Use with setVisibility(int).

    See View.GONE and View.INVISIBLE

    0 讨论(0)
  • 2021-02-05 09:45

    invisible will take up the same space as if it were visible. Set the visibility to gone if you want it to take up no space.

    0 讨论(0)
  • 2021-02-05 09:47

    The documentation of Invisible says:

    This view is invisible, but it still takes up space for layout purposes.

    So setting the visibility of layout to invisible just hides the layout, but does not free the consumed space. If you want to do that you have to set the visibility to gone.

    Gone does what you want:

    This view is invisible, and it doesn't take any space for layout purposes.

    See also: http://developer.android.com/reference/android/view/View.html#setVisibility(int)

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