Reputation: 619
I am trying to create a header that is a little similar to the facebook android app. The header should have a header title in the middle with a button on each side.
I have the header title but my code below does not show either button. I'm not sure if this info helps but the TableRow layout for this header is taking up a lot of height space. It used to wrap the until the title's height until I attempted adding buttons.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#008000" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/menuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/HeaderTextView"
android:text="Button" />
<TextView
android:id="@+id/HeaderTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/header"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:textColor="#FFF"
android:textStyle="italic" />
<Button
android:id="@+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/HeaderTextView"
android:text="Button" />
</RelativeLayout>
</TableRow>
</TableLayout>
Upvotes: 0
Views: 90
Reputation: 1778
This works for me. For what ever reason, the android:layout_weight="1"
makes it work.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="@+id/menuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Button" />
<TextView
android:id="@+id/HeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="This is the title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFfff"
android:textStyle="italic" />
<Button
android:id="@+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
Upvotes: 2
Reputation: 2182
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
<Button
android:id="@+id/menuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Button" />
<TextView
android:id="@+id/HeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="@id/menuButton"
android:layout_toLeftOf="@+id/infoButton"
android:text="headersfasfsdfsdfsdfsdfsdf"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:textStyle="italic" />
<Button
android:id="@+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
</TableLayout>
Upvotes: 0