EditText resizes for no reason… here is a solution to the problem.
EditText resizes for no reason
Rather strange behavior is observed in the relative layout.
Here is the initial state:
Defined as:
<EditText
android:id="@+id/bleedCount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/abrMult"
android:layout_below="@+id/textView4"
android:layout_marginRight="10dp"
android:ems="10"
android:inputType="number"
>
<requestFocus />
</EditText>
<TextView
android:id="@+id/abrMult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/abrSubmit"
android:layout_alignBaseline="@+id/abrSubmit"
android:layout_marginRight="10dp"
android:text="x12" />
<Button
android:id="@+id/abrSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView4"
android:layout_alignParentRight="true"
android:text="Calculate" />
On onItemSelected
in the drop-down list, it’s changing like this:
abrSubmit.setText(pos == 1 ? "Calculate" : "Submit");
abrMult.setVisibility(pos == 1 ? View.VISIBLE : View.GONE);
bleedCount.setHint(pos == 1 ? "# of Meow/month" : "# of Meow/year");
Then it becomes like this:
Notice the height of EditText bleedCount
on the second image. The value of bleedCount.getHeight()
changed from 72 to 95, and I don’t understand what caused it.
Solution
It is related to android:ems="10"
Related
When EditText changes its width, it must be split into two lines after displaying the View at x12
.
>ems The size of a given font is one letter.
I don’t think you need ems
.
Set EditText to single line: android:singleLine="true"