I’m dynamically generating a layout, and to do this I have a menu_row_element.xml file which contains the repeating row structure.
It consists of a LinearLayout (horizontal) which contains an image, a larger text above a smaller one, and an ImageView with a right arrow (inside another LinearLayout to keep it right aligned).
When the text part is small, everything looks fine. However if the text part is long, the right arrow is pushed off the screen.
How can I keep the right arrow always right aligned on the screen and have the textviews wrap the text appropriately?
In this image, the last row is OK since the text is small, but rows 1 and 2 push the right arrow off the screen.
a busy cat http://img706.imageshack.us/img706/2927/device20111221203115.jpg
The xml file is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="true"
android:background="@drawable/main_menu_button"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal"
android:gravity="left|center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Icon of each section -->
<ImageView
android:id="@+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:padding="10px" />
<!-- Text, in two parts -->
<LinearLayout
android:orientation="vertical"
android:paddingLeft="10px"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<!-- Big font text -->
<TextView
android:id="@+id/menu_element_big_text"
android:textSize="20dp"
android:textColor="@color/black"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<!-- Small font text -->
<TextView
android:id="@+id/menu_element_small_text"
android:scrollHorizontally="false"
android:textSize="15dp"
android:textColor="@color/black"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- Layout just to be able to right align, sheesh! -->
<LinearLayout
android:gravity="right|center_vertical"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:padding="0dp"
android:src="@drawable/right" />
</LinearLayout>
</LinearLayout>
Thanks!
Use a
RelativeLayout.The structure should be then:
Or if you prefer (and this is actually probably better), do this: