Evgeny Borzenkov Evgeny Borzenkov - 3 months ago 14
Android Question

maxWidth doesn't work with fill_parent

When using

fill_parent
,
maxWidth
has no effect.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxWidth="50dip"/>
</LinearLayout>
</LinearLayout>

Sam Sam
Answer

The attribute maxWidth has no effect on a width of match_parent (or the deprecated fill_parent), they are mutually exclusive. You need to use wrap_content.

Also any layout that only has one child can probably be removed, for instance you can simplify you current layout to:

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:maxWidth="50dip"/>
Comments