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?
LinearLayout means you can align views one by one (vertically/ horizontally). RelativeLayout means based on relation of views from its parents and other views.
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.
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...
Because you have to set the visibility to gone
if you want that the view takes no space.
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)
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With