代码之家  ›  专栏  ›  技术社区  ›  Robby Pond

Android布局,带2个等距按钮

  •  7
  • Robby Pond  · 技术社区  · 14 年前

    我有一个正确的布局,一个相对的布局,有一个文本视图和两个按钮,在下面均匀分布。

    <RelativeLayout android:id="@+id/entrypopup"
                android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:padding="5px"
        android:visibility="gone"
        android:layout_below="@+id/ad"
        android:background="#80000000">
        <TextView android:id="@+id/title" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:text="Entry Popup..."
            android:textColor="#ffffffff"
            android:textSize="20sp" />
        <TableLayout android:id="@+id/TableLayout01"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_below="@id/title">
            <TableRow android:layout_weight="1">
                <Button android:id="@+id/buttonVisit" android:text="View"
                    android:layout_height="fill_parent"
                    android:layout_width="0dip"
                    android:layout_weight="1"/>
                <Button android:id="@+id/buttonCancel" android:text="Cancel"
                    android:layout_width="0dip"
                    android:layout_weight="1" 
                    android:layout_height="fill_parent"/>
            </TableRow>
        </TableLayout>
    </RelativeLayout>
    

    但是运行layoutopt它会说“这个TableRow布局或者它的TableLayout父级可能是无用的”。

    有没有一种方法可以在没有桌子的情况下进行这种布局?

    1 回复  |  直到 14 年前
        1
  •  11
  •   CommonsWare    14 年前

    倒垃圾 TableLayout TableRow ,只需使用水平 LinearLayout 在他们的位置上。“魔力”就在你的心里 0dip 宽度和 1 重量,你已经有了。