layout_gravity="bottom" 失效

一、概述
在LinearLayout布局下,对Bottom添加属性 layout_gravity="bottom" 失效。[xhtml] view plain copy

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:<a href="http://lib.csdn.net/base/android" class='replace_word' title="Android知识库" 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的布局,所以竖直方向上有可能同时存在多个widgets。如果有两个或两个以上的widgets设置了android:layout_gravity="bottom"属性,那么系统就不能分辨出到底哪个widget放置在底部。所以在LinearLayout的vertical布局下,android:layout_gravity="bottom"无效。

二、解决方法
可以通过RelativeLayout布局android:layout_alignParentBottom="true"来实现放置底部效果。[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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容