是否有更好的方法来做到这一点,即按钮在屏幕两侧底部对齐?重要的部分是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 父级没有用
最佳答案
试试这个
<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>
关于android - 布置底部对齐的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9543005/