Android布局中LinearLayout的android:layout_gravity="bottom"不起作用
16lz
2021-01-24
在做界面布局的时候,我们经常用到的就是LinearLayout,但是有时候用起来也不方便,比如我们在页面中要把一个Button放在屏幕底部,此时我们设置android:layout_gravity="bottom"是没有效果的。为什么呢?对于 LinearLayout:
当 android:orientation="vertical"时, 只有水平方向的设置才起作用,垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
当 android:orientation="horizontal" 时, 只有垂直方向的设置才起作用,水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。
如果我们要实现在手机屏幕上把某一个View放在底部,可以在我们布局的xml的最外层(或根布局)用RelativeLayout。再在RelativeLayout中包含我们写好的LinearLayout,把要显示在手机屏幕底端的view要加上属性android:layout_alignParentBottom="true",这样就可以了。
更多相关文章
- android 键盘顶起布局底部
- Android原理揭秘系列之View、ViewGroup
- 精通 Android(安卓)中的 tools 命名空间
- Android上实现仿IOS弹性ScrollView
- Android(java)学习笔记95:Android原理揭秘系列之View、ViewGroup
- Android(安卓)GridLayout 动态添加子控件 + 平均分配空间
- Android中常用布局单位
- android listview 中 item显示表格样式
- Android(安卓)布局中长度单位的深入研究