Reputation: 18531
It seems that maxWidth has no effect on EditText. Could anyone shed some light on this?
<EditText
android:id="@+id/editTextFoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autofillHints="port"
android:ems="10"
android:maxWidth="100dp"
tools:targetApi="o" />
The above code results in the following:
If I set layout_width="100dp" as following:
<EditText
android:id="@+id/editTextFoo"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:autofillHints="port"
android:ems="10"
android:maxWidth="100dp"
tools:targetApi="o" />
Upvotes: 0
Views: 127
Reputation: 1525
Yes I just checked in the IDE and it's because ems="10"
is preventing the view from maintaining maxWidth 100dp. Apparently ems of 10 requires a larger width so it is overriding the maxWidth attribute.
Instead of ems go with minWidth to prevent the view from shrinking.
Alternatively, you can use maxEms
and minEms
.
Upvotes: 1