I am trying to execute the following layout:
+----------------------------------------+ | [icon] [text] [icon] | +----------------------------------------+ | [icon] [very loooooooooooooooooo [icon]| | oooooooooooooooong text] | +----------------------------------------+
When the text is short, the icon on the right should be next to the text (not aligned right). When the text is long, I need text to wrap.
I tried using LinearLayout and RelativeLayout, but the icons are still wiped out when I have long text. Here are the layouts I tried:
LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="left"/> <TextView android:id="@+id/middle" android:text="a long long string, a long long string, a long long string, a long long string, a long long string, a long long string, " android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#D0E198"/> <TextView android:id="@+id/right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="right"/> </LinearLayout>
RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="left"/> <TextView android:id="@+id/middle" android:text="a long long string, a long long string, a long long string, a long long string, a long long string, a long long string, " android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#D0E198" android:layout_toRightOf="@id/left"/> <TextView android:id="@+id/right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="right" android:layout_toRightOf="@id/middle"/> </RelativeLayout>
In both cases, the icon on the right is pushed out of the screen.
I also tried LinearLayout with layout_weight = "1" left and right and 0 on the middle screen. This pushes both icons off the screen.
source share