Android 在TableRow布局中对齐组件

Android 在TableRow布局中对齐组件,android,xml,Android,Xml,我正在尝试创建一个类似于facebook android应用程序的标题。标题应该中间有标题标题,每边都有一个按钮。< /P> 我有标题,但我下面的代码没有显示任何按钮。我不确定这个信息是否有用,但是这个标题的TableRow布局占用了很多高度空间。在我尝试添加按钮之前,它一直包装标题直到标题的高度 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schem

我正在尝试创建一个类似于facebook android应用程序的标题。标题应该中间有标题标题,每边都有一个按钮。< /P> 我有标题,但我下面的代码没有显示任何按钮。我不确定这个信息是否有用,但是这个标题的TableRow布局占用了很多高度空间。在我尝试添加按钮之前,它一直包装标题直到标题的高度

<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>


这对我很有用。无论出于什么原因,
android:layout\u weight=“1”
都能让它工作

<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>

谢谢您的回答!这有所帮助,但目前,按钮贴在标题附近。我希望按钮靠近屏幕的左右边缘。我应该使用哪个命令?
<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>