2-1 布局管理器

14 篇文章 0 订阅
11 篇文章 0 订阅

布局管理器

LinearLayout(线性布局)
RelativeLayout(相对布局)

2-1-1 LinearLayout

常用属性

android:id 查找控件的唯一标识
android:layout_width 宽度
android:layout_height 高度
android:background 背景
android:layout_margin 外边距
android:layout_padding 内边距
android:orientation 方向(默认水平方向,线性布局特有)

使用:

<LinearLayout
	android:id="@+id/ll_1"
	android:layout_width=""
	android:layout_height=""
	android:orientation="">

</LinearLayout>
	

其中:

  1. layout_width、layout_height属性值分为:
    wrap_content 包含内容,内容多少宽度即为多少;
    match_parent 匹配父控件
  2. orientation属性值为:
    horizontal 水平方向
    vertical 垂直方向

注意:
android 中的宽度高度单位为 dp e.g. 100dp
android 中的字体单位为 sp e.g. 10sp
这是由于android 屏幕碎片化较严重,有各种机型、分辨率等。
dp、sp 可根据分辨率自己适配、计算出单位来。

<View 
	android:id="@+id/v_1"
	android:layout_width="0dp"
	android:layout_weidht="1"/>
<View 
	android:id="@+id/v_2"
	android:layout_width="0dp"
	android:layout_weight="1"/>
  1. 是所有控件的父类,TextView、Button等最终都继承自 View,
    View 的父控件是 LinearLayout
  2. gravity 内部元素排放的对其方式
  3. layout_weight 权重,将剩余内容按照权重进行分配
    上述代码中设置的两个View中layout_weight均为“0dp”,权重均为“1”,所以以上两个View将剩余内容平分,各占一半。

2-1-2 RelativeLayout

最常用属性:
android:layout_toLeftOf 在…的左边
android:layout_toRightOf 在…的右边
android:layout_alignButton 与…的底部对齐
android:layout_alignParentBottom 与父控件底部对齐
android:layout_brlow 在…的下边

使用:
android:layout_below="@+id/view_1" 在view_1的下面
android:layout_toRightOf="@+id/view_1" 在view_1的右边

其他用法与LinearLayout(线性布局)基本相同

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值