I have two views within a LinearLayout
, both of which should wrap_content
such that they are minimally large enough to display their content. The LinearLayout
view group should wrap_content
of the two child groups such that it is just large enough to display the content of both child views.
But after this, if one of the two child views is larger, the other child view should expand to match parent to fill the remaining space available to it. The content of the two child views is dynamic and is unknown which will be larger at runtime.
The two child views are a TextView
and a Spinner
. The Spinner
should fill any remaining space in the LinearLayout
width. But if I change the Spinner
layout_width
to match_parent
and the TextView
is not large enough, the Spinner
will truncate its contents.
Basically I need a way to choose the maximum width between wrap_content
and match_parent
.
This is the layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parentView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:layout_marginBottom="-2dp"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:textSize="12sp"
android:textColor="?android:textColorHint"
tools:text="Label" />
<Spinner
android:id="@+id/spinner"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- or android:layout_width="match_parent"? need max of both... -->
</LinearLayout>