简体   繁体   中英

removing a Button from a LinearLayout

Is it possible to remove a Button from a LinearLayout that the free space can be used by other objects?

I only know this which makes the Button invisible.

.setVisibility(View.INVISIBLE);

Kind Regards,

kj

you need to just change invisible to gone like below code:

yourbutton.setVisibility(View.GONE);

if you are using gone it's hide button with remove occupy space in layout!

after you need show button using visible it's automatically re-occupy spaces for a button in layout like below sample code:

yourbutton.setVisibility(View.VISIBLE);

if you are invisible it's hides only button and it's does not remove occupy space button in layout like below code:

yourbutton.setVisibility(View.INVISIBLE);

Try the below

   .setVisibility(View.GONE)

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

public static final int GONE

Added in API level 1

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

Constant Value: 8 (0x00000008)

public static final int INVISIBLE

Added in API level 1

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

you can change the visibility of the button to GONE ,using

textView.setVisibility(View.GONE)     

using View.INVISIBLE will make the view still take space, so it's probably not what you want.

another alternative is to really remove it , by using:

linearLayout.removeView(textView);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM