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

Android LinearLayout 如何让子元素靠下居中对齐 center bottom

Android LinearLayout 如何让子元素靠下居中对齐 center bottom

首先你需要知道两个知识点:

  • android:layout_gravity 指定的是当前元素在父元素中的位置
  • android:gravity 指定的是当前元素子元素的排布位置

比如:

有这么一个布局,我需要让它靠下居中对齐,LinearLayout 上的 gravity = center 是对的,指定的是它的子元素应该居中排布。

在这里插入图片描述

<LinearLayoutandroid:gravity="center"android:orientation="horizontal"android:layout_marginBottom="20dp"android:layout_width="match_parent"android:layout_height="wrap_content"><ImageViewandroid:layout_marginEnd="10dp"android:layout_width="35dp"android:layout_height="35dp"android:src="@mipmap/ic_launcher"></ImageView><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/white"android:text="蓝牙权限状态"android:textSize="24dp"android:textFontWeight="600"/><TextViewandroid:layout_marginLeft="10dp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/gary"android:text="@string/version"android:textSize="16dp"/>
</LinearLayout>

那么如何让子元素靠下排列呢?那就是子元素该定义的了,所以我们在每个子元素中再添加 layout_gravity = bottom 即可。

在这里插入图片描述

http://www.lryc.cn/news/305816.html

相关文章:

  • 物体检测-系列教程16:YOLOV5 源码解析6(马赛克数据增强函数load_mosaic)
  • 星河做市基金会全球DAO社区启动,为数字货币市场注入新活力
  • QT Widget自定义菜单
  • UnityWebGL 设置全屏
  • 100224. 分割数组
  • WSL2配置Linux、Docker、VS Code、zsh、oh my zsh(附Docker开机自启设置)
  • 深度学习基础(四)医疗影像分析实战
  • ChatGPT调教指南 | 咒语指南 | Prompts提示词教程(一)
  • LeetCode | 两数相加 C语言
  • 【Spring MVC】处理器映射器:AbstractHandlerMethodMapping源码分析
  • 网络编程知识整理
  • 【小白友好】leetcode 移动零
  • 迭代、递归、尾递归实现斐波那契数列的第n项
  • vulnhub靶场之driftingblues-1
  • NGINX服务器配置实现加密的WebSocket连接WSS协议
  • 5个免费文章神器,用来改写文章太方便了
  • 详细教程!VMware Workstation Pro16 安装 + 创建 win7 虚拟机!
  • Python文件和异常(二)
  • 大模型+影像:智能手机“上春山”
  • 8-pytorch-损失函数与反向传播
  • MySQL高级特性篇(8)-数据库连接池的配置与优化
  • mac下使用jadx反编译工具
  • 分布式一致性软件-zookeeper
  • 企业计算机服务器中了babyk勒索病毒怎么办?Babyk勒索病毒解密数据恢复
  • 板块一 Servlet编程:第五节 Cookie对象全解 来自【汤米尼克的JAVAEE全套教程专栏】
  • 自动驾驶---Motion Planning之Path Boundary
  • Leetcode 3048. Earliest Second to Mark Indices I
  • 从源码学习单例模式
  • axios介绍和使用
  • redis雪崩问题