线性布局 简单地说就是控件或者布局按照水平方向或者垂直方向依次排列! 垂直方向 标签内属性为 Android:orientation="vert
简单地说就是控件或者布局按照水平方向或者垂直方向依次排列!
垂直方向
标签内属性为
Android:orientation="vertical"
水平方向
标签内属性为
android:orientation="horizontal"
其中LinearLayout的排列方向为水平时,内部控件的宽度不可以指定为match_parent,其中LinearLayout的排列方向为垂直时,内部控件的高度不可以指定为match_parent
在Button中添加android:layout_gravity
属性
该属性指定控件在布局中的位置
此时当线性布局中属性android:orientation的属性值为"horizontal",android:layout_gravity只有在垂直方向上有效。
此时当线性布局中属性android:orientation的属性值为"vertical",android:layout_gravity只有在水平方向上有效。
布局中的android:layout_weight
该属性允许我们使用布局的方式指定控件的大小
想看代码和效果
此时我们虽然将
android:layout_width="0dp"
设置成0dp,但是控件依然会显示出来,此时他们的的宽度由android:layout_weight
决定android:layout_weight
为2,控件2的android:layout_weight
的值为3.则控件1在水平方向上占sum2/5,控件1在水平方向上占sum3/5。
假如我们将Button的宽度设置为wrap_content结果会如何呢?
Button将会按照wrap_content计算而EditText会占满屏幕所有的剩余空间
android:layout_alignLeft表示一个控件的左边缘与另一个空间的左边缘对齐。
android:layout_alignRight表示一个控件的右边缘与另一个空间的右边缘对齐。
--结束END--
本文标题: Android学习之4种基本布局
本文链接: https://www.lsjlt.com/news/29185.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0