<Android>布局中gravity和layout_gravity区别

概念

1、android:layout_gravity是设置该控件相对于父容器对齐方式;
2、android:gravity是设置子元素在该容器内的对齐方式。(若其下没有子元素,此项无效;若父子产生冲突,以子元素为准。)
3、layout_gravity和gravity可以设置的值:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。
在这里插入图片描述

如图

在这里插入图片描述2022.05.23于长安

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码是一个 LinearLayout 布局,包含一个 TextView、一个 LinearLayout 和一个 Button。 LinearLayout 的属性: - android:layout_width="match_parent":表示布局宽度与父布局的宽度一致。 - android:layout_height="match_parent":表示布局高度与父布局的高度一致。 - android:orientation="vertical":表示子视图垂直排列。 TextView 的属性: - android:layout_width="match_parent":表示宽度与父布局宽度一致。 - android:layout_height="wrap_content":表示高度根据文本内容自适应。 - android:layout_gravity="center_horizontal":表示水平居对齐。 - android:padding="20dp":表示内边距为 20dp。 - android:text="计算您的星座":表示文本内容为 “计算您的星座”。 LinearLayout 的属性: - android:layout_width="match_parent":表示宽度与父布局宽度一致。 - android:layout_height="wrap_content":表示高度根据子视图自适应。 - android:id="@+id/linearLayour1":表示该 LinearLayout 的 ID 为 “linearLayour1”。 - android:layout_gravity="center_vertical":表示垂直居对齐。 TextView 的属性: - android:layout_width="wrap_content":表示宽度根据文本内容自适应。 - android:layout_height="wrap_content":表示高度根据文本内容自适应。 - android:id="@+id/textView1":表示该 TextView 的 ID 为 “textView1”。 - android:text="阳历生日:":表示文本内容为 “阳历生日:”。 EditText 的属性: - android:id="@+id/birthday":表示该 EditText 的 ID 为 “birthday”。 - android:layout_width="wrap_content":表示宽度根据文本内容自适应。 - android:layout_height="wrap_content":表示高度根据文本内容自适应。 - android:minWidth="100dp":表示最小宽度为 100dp。 - android:minHeight="48dp":表示最小高度为 48dp。 TextView 的属性: - android:layout_width="wrap_content":表示宽度根据文本内容自适应。 - android:layout_height="wrap_content":表示高度根据文本内容自适应。 - android:id="@+id/textView2":表示该 TextView 的 ID 为 “textView2”。 - android:text="格式:YYYY-MM-DD 例如:2012-01-01":表示文本内容为 “格式:YYYY-MM-DD 例如:2012-01-01”。 Button 的属性: - android:layout_width="wrap_content":表示宽度根据文本内容自适应。 - android:layout_height="wrap_content":表示高度根据文本内容自适应。 - android:id="@+id/button1":表示该 Button 的 ID 为 “button1”。 - android:text="确定":表示文本内容为 “确定”。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值