I have an EditText and a Spinner in a horizontal layout. I’d like the spinner to be only as large as necessary to hold its widest text and the EditText to take the remaining space. Is there an easy way to do this?
For example, ideally, I’d like to specify the spinner’s width as some multiple of the average font width, declared as an attribute in the xml file.
Otherwise, I suppose I need to do something at runtime such as get the text width of each item in the spinner and take the max + some allowance for the radio-button icon.
This is my xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="@+id/text"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/text" />
<Spinner
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:textAppearance="@android:style/TextAppearance.Medium" />
</LinearLayout>
Thanks.
try this