Horizonal LinearLayout with max width TextView
I have a LinearLayout with horizontal orientation and two TextView
children. My goal is to have the left TextView expand to fit its text
content, but only up to a maximum width (to leave room for the right
TextView). The key is I want to be able to express this maximum width in
terms of a percentage similar to the way layout_weight is specified.
The problem with setting the layout_weight is that the TextView is then
unconditionally expanded to fill the maximum width, even if the contents
don't require the extra space.
Here's my current layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/subject"
android:textSize="18sp"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.8"/>
<TextView android:id="@+id/date"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Thanks!
No comments:
Post a Comment