【问题标题】:Laying out bottom-aligned buttons布置底部对齐的按钮
【发布时间】:2012-03-03 11:54:40
【问题描述】:

有没有更好的方法来做到这一点,使按钮在屏幕两侧底部对齐?重要的部分是 alignParentBottom,它似乎只在 RelativeLayout 中可用,以及 layout_gravity,它似乎只在 LinearLayout 及其子类(如 TableLayout)中可用,RelativeLayout 不是其中之一。

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1">
            <TableRow>
                <Button
                    android:id="@+id/list_delete"
                    android:text="@string/list_delete"
                    android:visibility="invisible"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />
                <Button
                    android:id="@+id/list_save"
                    android:text="@string/list_add"
                    android:layout_gravity="right"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />
            </TableRow>
        </TableLayout>
    </RelativeLayout>

Android lint 给我这样的错误:

  • 这个 TableLayout 布局或者它的 RelativeLayout 父级是没用的
  • 此 TableRow 布局或其 TableLayout 父级无用

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    试试这个

       <RelativeLayout//this will be your parent layout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
    
    
                <Button
                    android:id="@+id/list_delete"
                    android:text="@string/list_delete"
                    android:visibility="invisible"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />
                <Button
                    android:id="@+id/list_save"
                    android:text="@string/list_add"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />
    
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-04
      • 2017-01-29
      • 2019-07-26
      • 2021-05-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多