一、概述
在LinearLayout布局下,對(duì)Bottom添加屬性 layout_gravity="bottom" 失效。[xhtml] view plain copy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:<a class='replace_word' title="Android知識(shí)庫" target='_blank' style='color:#df3434; font-weight:bold;'>Android</a>="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
</Button>
</LinearLayout>
我覺得原因是LinearLayout 是豎直排列widgets的布局,所以豎直方向上有可能同時(shí)存在多個(gè)widgets。如果有兩個(gè)或兩個(gè)以上的widgets設(shè)置了android:layout_gravity="bottom"屬性,那么系統(tǒng)就不能分辨出到底哪個(gè)widget放置在底部。所以在LinearLayout的vertical布局下,android:layout_gravity="bottom"無效。
二、解決方法
可以通過RelativeLayout布局android:layout_alignParentBottom="true"來實(shí)現(xiàn)放置底部效果。[xhtml] view plain copy
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/ProcessBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Process">
</Button>
</RelativeLayout>