I have a very simple problem, but I am clearly doing something wrong. I’ve tried many ways to do this, but there’s always something screwing up.
I have a ListView with a horizontal LinearLayout serving as a header. I want to have < and > serving as “back and next” widgets, on the very left and very right portions of the LinearLayout. The LIST HEADER portion should be centered between them.
Making LIST HEADER have the attribute android:layout_width="match_parent" cuts off the right hand arrow. Otherwise it lays on top of the left arrow, even though it appears after the LIST HEADER TextView in the XML file.
< LIST HEADER > List item number 1 List item number 2 List item number 3
I’m not new to Android at this stage but this seems basic. Any help would be appreciated.
I should add that I’m not using eclipse.
CURRENT XML (sort of messy after trying so many things, apologies):
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/LeftFormulaHeaderLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="@dimen/text_huge"
android:id="@+id/LeftFormulaHeader"
android:text="<"/>
</RelativeLayout>
<TextView
android:layout_width="200dip"
android:layout_height="wrap_content"
android:textSize="@dimen/text_huge"
android:ellipsize="end"
android:scrollHorizontally="false"
android:singleLine="true"
android:gravity="center"
android:id="@+id/FormulaHeader"/>
<RelativeLayout
android:id="@+id/RightFormulaHeaderLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/RightFormulaHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textSize="@dimen/text_huge"
android:text=">"/>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<ListView
android:id="@+id/TheList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000033"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
<TextView
android:id="@+id/empty_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:text="@string/empty_list" />
</LinearLayout>
Your main issue:
gravityaffects positioning of the text within theTextView. You wantalignParentLeft/-RightandcenterHorizontalfor what you are doing (althoughgravity="center"remains to keep the header centered in its view).