Having trouble getting a simple RelativeLayout going. I'm building a ListView composed of rows which should look like this:
+-----------------------------+--------------+
| Line 1 | Small button |
| Line 2, more text | |
| Line 3, even more text | |
Here's my first attempt - unfortunately the vertical divider does not show up.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/lineOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/wallet_holo_blue_light"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/lineTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lineOne"
android:textSize="16dp" />
<TextView
android:id="@+id/lineThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lineTwo"
android:textSize="14dp" />
<ImageButton
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:focusable="false"
android:focusableInTouchMode="false"
android:onClick="doSomething"
android:src="@drawable/arrow_down" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/myButton"
android:background="?android:attr/listDivider" />
</RelativeLayout>
EDIT: I almost solved my own problem with the code below.
Now my layout looks good...
+-----------------------------+--------------+
| Line 1 | Small button |
| Line 2, more text | |
| Line 3, even more text | |
... except when the first line for instance is too long - in such case the divider and the button don't show up:
+-----------------------------+--------------+
| Line 1, way way way way too long which |
| wraps |
| Line 2, more text |
| Line 3, even more text |
Could you kindly help me make the final adjustment?
Thanks a lot!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/lineOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/wallet_holo_blue_light"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/lineTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp" />
<TextView
android:id="@+id/lineThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp" />
</LinearLayout>
<!-- As per http://stackoverflow.com/questions/6992804/how-to-right-align-widget-in-horizontal-linear-layout-android -->
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="?android:attr/listDivider" />
<ImageButton
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/arrow_down" />
</LinearLayout>
</LinearLayout>