Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinearLayout: layout_width vs. minWidth

Tags:

android

I'm trying to have a layout in a certain width, using the layout_width property, but when inflated - the width of the layout is taken from the child, which is smaller then the layout_width I stated. Here's an example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/blabla"
android:orientation="vertical"
android:layout_width="310dip"
android:layout_height="fill_parent"
>
    <TextView android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="60dip"
    android:paddingTop="15dip"
    android:paddingLeft="23dip"
    android:text="udini "
    />
</LinearLayout>

This code make the entire layout be in the width of 60dip. But when adding the minWidth attribute to the layout, with the value 310dip, then the width of the layout is as expected.

Why is it like that? Is the layout_width attribute just a suggestion?

Thanks,

Udi

like image 768
Udinic Avatar asked Apr 17 '11 10:04

Udinic


People also ask

Which has better performance LinearLayout or RelativeLayout?

So Linear Layout should preferred over Relative Layout! Also if you use weight_sum attribute within Linear Layout it would again “measure the child twice”. So avoid using this attribute as much as possible.

What's the difference between LinearLayout and RelativeLayout?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.

What is the difference between Framelayout and LinearLayout in Android?

Definitions: Frame Layout: This is designed to block out an area on the screen to display a single item. Linear Layout: A layout that arranges its children in a single column or a single row. Relative Layout: This layout is a view group that displays child views in relative positions.

Is LinearLayout a ViewGroup?

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.


1 Answers

LinearLayouts are not required to honour the layout_width attribute when it's not set to wrap_content or fill_parent.

You can still use android:minWidth if that's enough for you, or other options are using the android:layout_weight attribute or increase the android:padding attribute on the child.

like image 52
Aleadam Avatar answered Sep 20 '22 07:09

Aleadam