LinearLayout: layout_width vs. minWidth
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="60d开发者_如何学运维ip"
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
LinearLayout
s 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.
精彩评论