Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a LinearLayout which is invisible take up space?

I've got the following LinearLayout...

<LinearLayout android:id="@+id/linearLayout3" android:visibility="invisible" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/S"></TextView>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/b"></TextView>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/Ar"></TextView>
</LinearLayout>

I've set the visibly to invisible but the LinearLayout still takes up space causing padding between two other linearlayouts in the layout, why? How do I make it take up no space?

like image 755
Skizit Avatar asked Apr 22 '11 14:04

Skizit


People also ask

What is the difference between RelativeLayout and LinearLayout?

LinearLayout means you can align views one by one (vertically/ horizontally). RelativeLayout means based on relation of views from its parents and other views.

What is the use of LinearLayout?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.

How do you set LinearLayout to the bottom?

Just add layout_weight="1" to in your linearLayout which having Buttons. adding anroid:layout_weight="1" does not move the linear layout (and buttons) down to the bottom...


4 Answers

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

like image 61
Guillaume Brunerie Avatar answered Oct 17 '22 14:10

Guillaume Brunerie


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)

like image 40
RoflcoptrException Avatar answered Oct 17 '22 14:10

RoflcoptrException


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

like image 25
OcuS Avatar answered Oct 17 '22 14:10

OcuS


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.

like image 45
james Avatar answered Oct 17 '22 15:10

james