当前位置: 首页 > wzjs >正文

网站推广软件价格郑州做网站排名

网站推广软件价格,郑州做网站排名,学生个人网页制作素材,wordpress 替代品文章目录 **1. 常用取值****示例** **2. layout_gravity(控制 View 在父容器中的对齐方式)****常用取值****示例** **3. gravity vs layout_gravity 对比****4. 注意事项****5. 总结** 作用对象:当前 View 的内部内容(如 TextView…

文章目录

    • **1. 常用取值**
      • **示例**
    • **2. `layout_gravity`(控制 View 在父容器中的对齐方式)**
      • **常用取值**
      • **示例**
    • **3. `gravity` vs `layout_gravity` 对比**
    • **4. 注意事项**
    • **5. 总结**

在这里插入图片描述

作用对象:当前 View 的内部内容(如 TextView 的文本、Button 的文字、LinearLayout 的子控件等)。
适用控件TextViewButtonLinearLayoutRelativeLayout 等几乎所有 View。

1. 常用取值

说明
left / start左对齐(start 适配 RTL 布局)
right / end右对齐(end 适配 RTL 布局)
top顶部对齐
bottom底部对齐
center水平 + 垂直居中
center_horizontal水平居中
center_vertical垂直居中
fill / fill_horizontal / fill_vertical填充(较少使用)

示例

<!-- TextView 的文本居中 -->
<TextViewandroid:layout_width="200dp"android:layout_height="100dp"android:text="Hello World"android:gravity="center" />  <!-- 文本在 TextView 内部居中 --><!-- LinearLayout 的子控件垂直居中 -->
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="200dp"android:gravity="center_vertical">  <!-- 所有子控件垂直居中 --><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button 1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button 2" />
</LinearLayout>

2. layout_gravity(控制 View 在父容器中的对齐方式)

作用对象:当前 View 在其父容器 中的位置(如 Button 在 LinearLayout 中的对齐方式)。
适用控件:主要用于 LinearLayoutFrameLayout 的子控件(RelativeLayoutConstraintLayout 一般不用)。

常用取值

说明
left / start靠左(start 适配 RTL)
right / end靠右(end 适配 RTL)
top靠顶部
bottom靠底部
center居中
center_horizontal水平居中
center_vertical垂直居中
fill_horizontal水平填充(拉伸)
fill_vertical垂直填充(拉伸)

示例

<!-- FrameLayout 中的 Button 居中 -->
<FrameLayoutandroid:layout_width="match_parent"android:layout_height="200dp"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Click Me"android:layout_gravity="center" />  <!-- Button 在 FrameLayout 中居中 -->
</FrameLayout><!-- LinearLayout 中的 Button 靠右 -->
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button 1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button 2"android:layout_gravity="end" />  <!-- Button 2 靠右 -->
</LinearLayout>

3. gravity vs layout_gravity 对比

属性作用对象适用场景示例
gravity当前 View 的内部内容TextView 文本居中、LinearLayout 子控件对齐android:gravity="center"
layout_gravity当前 View 在其父容器中的位置Button 在 FrameLayout 居中、View 在 LinearLayout 靠右android:layout_gravity="center"

4. 注意事项

  1. layout_gravityLinearLayout 中的限制

    • 如果 LinearLayouthorizontal 方向,layout_gravity 只能控制 垂直方向top/bottom/center_vertical)。
    • 如果 LinearLayoutvertical 方向,layout_gravity 只能控制 水平方向left/right/center_horizontal)。
  2. ConstraintLayout 替代方案

    • ConstraintLayout 一般不使用 layout_gravity,而是用 app:layout_constraintXXX_toXXXOf="parent" 控制位置:

      <Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" />
      
  3. gravitylayout_gravity 可以组合使用

    <LinearLayoutandroid:layout_width="match_parent"android:layout_height="200dp"android:gravity="center">  <!-- 子控件整体居中 --><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button"android:layout_gravity="end" />  <!-- 但 Button 自己靠右 -->
    </LinearLayout>
    

5. 总结

  • gravity → 控制 当前 View 内部 的对齐(如文本、子控件)。
  • layout_gravity → 控制 当前 View 在父容器 中的对齐(如 Button 在 LinearLayout 中的位置)。
  • LinearLayout 方向影响 layout_gravity 的有效方向
  • ConstraintLayout 用约束替代 layout_gravity

掌握这两个属性可以更灵活地控制 Android 布局! 🚀


在 Android 布局中,layout_weight 是用于 LinearLayout 的一个属性,它允许子视图按照权重(weight)分配剩余空间,常用于实现比例布局(如按比例分配宽度或高度)。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


文章转载自:

http://Buoawaag.zsrjn.cn
http://vsVsvyHn.zsrjn.cn
http://NetaKF9X.zsrjn.cn
http://2KEOZ8jN.zsrjn.cn
http://MVzwKt8p.zsrjn.cn
http://KK3DV99O.zsrjn.cn
http://4jeOXioI.zsrjn.cn
http://7eHQuO6N.zsrjn.cn
http://BfnY5y9l.zsrjn.cn
http://PjMtlqBq.zsrjn.cn
http://7gZLX1RI.zsrjn.cn
http://C6YXmrYV.zsrjn.cn
http://je96JWgX.zsrjn.cn
http://hGtulyvQ.zsrjn.cn
http://lOY19ynq.zsrjn.cn
http://nHGycJ4v.zsrjn.cn
http://05erobnt.zsrjn.cn
http://pPw9gY0b.zsrjn.cn
http://tashxqwM.zsrjn.cn
http://67ZZTRHb.zsrjn.cn
http://CA0SePD8.zsrjn.cn
http://lmUCIl9b.zsrjn.cn
http://pZWydtBr.zsrjn.cn
http://bYYrCpwb.zsrjn.cn
http://rYdoFxf2.zsrjn.cn
http://30R4XLD9.zsrjn.cn
http://uPBXftho.zsrjn.cn
http://spT4BwTg.zsrjn.cn
http://rh6ZOSyK.zsrjn.cn
http://JCWEeAj8.zsrjn.cn
http://www.dtcms.com/wzjs/716451.html

相关文章:

  • 网站手机页面做多大企点下载官网
  • sns社交网站网站开发背景设置
  • 网站设计公司哪里好建设项目招标网站
  • 上海可以做网站的公司启信宝企业查询入口
  • 为什么四川省建设厅网站打不开佛山网站建设公司哪家最好
  • 辽宁同鑫建设有限公司网站网页设计工作室赚钱吗
  • 网站开发竞争对手分析加快建设乡镇招商网站
  • 网站应用市场设计定制衣服的厂家
  • 搜索设置 网站深圳市住房和建设局工程交易中心
  • 免费成品网站下载wordpress统计工具
  • 深圳网站seo设计公司电脑为什么有的网站打不开
  • 衍艺网站建设天津市网站建站制作
  • 给别人做网站如何收费没有网站也可以做推广吗
  • 视频网站推广phpcms网站备份
  • 开发的网站推广做网站怎么样
  • 什么是网站前台静态化海诚互联
  • 网站建设验收条款优化推广网站排名
  • 可以将自己做的衣服展示的网站台州网站优化方案
  • 有哪些做企业网站的无锡赛孚建设工程有限公司网站
  • 二手车交易市场骨科医院网站优化服务商
  • 免费网站建设基础步骤建设网站的技术方案是啥
  • 网站建设ppt简介长春关键词推广
  • 成都知名建筑公司排名舆情优化
  • 设备外贸用哪个网站用vue做网站的实例
  • 东莞网站建设制作公司黄页引流推广链接
  • 专业电子网站建设wordpress绑定手机版
  • 手机怎样做网站图解成都网站建设技术支持
  • 资源下载类网站源码下载了字体怎么安装到wordpress
  • 做爰试看的网站wordpress屏蔽主题更新
  • 广东省建设部网站wordpress flickr