How to hide a View programmatically?

前端 未结 3 1488
野趣味
野趣味 2020-11-27 12:11

In my application, I have 2 LinearLayout\'s right above each other. Via a menu option, I want to be able to make the bottom one disappear, and have the top one

3条回答
  •  天涯浪人
    2020-11-27 13:14

    You can call view.setVisibility(View.GONE) if you want to remove it from the layout.

    Or view.setVisibility(View.INVISIBLE) if you just want to hide it.

    From Android Docs:

    INVISIBLE

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

    GONE

    This view is invisible, and it doesn't take any space for layout purposes. Use with setVisibility(int) and android:visibility.

提交回复
热议问题