I have a horizontal linear layout with an image and a couple text views. In some languages (German…) the text is so long that to fit everything on one line, the layout would have to be wider than the screen. To prevent this, android automatically makes the text views wrap on to the next line.
Is there any way to choose which of the text views will end up wrapping? At the moment it appears that the last view added to the layout is the one that wraps. However I’d really like to have one of the earlier text views wrap and have the last text view always display on a single line. Is this possible? I’ve already subclassed most of the views involved so I can override protected methods.
Heres a rough outline of my code:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/some_icon" />
<TextView
android:id="@+id/can_wrap_if_neccessary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/some_really_long_text" />
<TextView
android:id="@+id/shouldnt_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/some_more_really_long_text" />
</LinearLayout
I figured it out: the solution is to set the layout_weight attribute on the view(s) that I want to wrap, and not set it at all on the views I don’t want to wrap. Any view with a layout_weight will wrap in preference over those without.