layout_gravity="bottom" 失效

一、概述
在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>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容