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

Android 约束布局ConstraintLayout整体链式打包居中显示

Android 用约束布局ConstraintLayout实现将多个控件视作一个整体居中显示,使用       app:layout_constraintHorizontal_chainStyle="packed"实现

chain 除了链条方向有横向和竖向区分外, chain链条上的模式有 3种

  •    spread - 元素将被展开(默认样式) 。加权链 - 在spread模式下,如果某些小部件设置为MATCH_CONSTRAINT,则它们将拆分可用空间 
  •    spread_inside - 类似,但链的端点将不会扩展 
  •    packed - 链的元素将被打包在一起。 孩子的水平或垂直偏差属性将影响包装元素的定位
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><!-- 作为父布局的 ConstraintLayout --><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_constraintVertical_chainStyle="packed"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"><!-- TextView 1 --><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintStart_toStartOf="parent"android:background="#ff0000"app:layout_constraintHorizontal_chainStyle="packed"android:text="Text 1"app:layout_constraintEnd_toStartOf="@+id/textView2"/><!-- TextView 2 --><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"app:layout_constraintTop_toTopOf="parent"android:background="#00ff00"app:layout_constraintBottom_toBottomOf="parent"android:text="Text 2"app:layout_constraintStart_toEndOf="@id/textView1" app:layout_constraintEnd_toStartOf="@id/textView3"/><TextViewandroid:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintRight_toRightOf="parent"android:background="#0000ff"android:text="Text 3"app:layout_constraintLeft_toRightOf="@id/textView2" /></androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

显示效果如下所示:

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

相关文章:

  • 在C#中,Array,List,ArrayList,Dictionary,Hashtable,SortList,Stack的区别
  • 微服务知识——微服务架构的演进过程
  • Chrome 浏览器:互联网时代的浏览利器
  • 深入浅出 NRM:加速你的 npm 包管理之旅
  • Linux——基础命令1
  • nuxt3中使用useFetch请求刷新不返回数据或返回html结构问题解决-完整nuxt3useFetchtch请求封装
  • Kubernetes 中 BGP 与二层网络的较量:究竟孰轻孰重?
  • C中静态库和动态库的使用
  • Debian 安装 Nextcloud 使用 MariaDB 数据库 + Caddy + PHP-FPM
  • 【FPGA】 MIPS 12条整数指令 【3】
  • Mac 部署Ollama + OpenWebUI完全指南
  • 蓝桥杯小白打卡第二天
  • Docker Compose:容器编排的利器
  • springboot项目的单元测试
  • JVM图文入门
  • cursor 开发java项目教程简单上手
  • 优化fm.jiecao.jcvideoplayer_lib中视频横竖屏自动适配原视频方案
  • aws(学习笔记第二十七课) 使用aws API Gateway+lambda体验REST API
  • 物联网的三层架构:感知层、网络层与应用层
  • 常用抓包工具tcpdump、Fiddler、Charles、Wireshark 和 Sniffmaster 下载地址
  • π0开源了且推出自回归版π0-FAST——打造机器人动作专用的高效Tokenizer:比扩散π0的训练速度快5倍但效果相当
  • js-对象-JSON
  • Houdini subuv制作输出阵列图
  • 虚幻基础17:动画蓝图
  • 路由器及工作原理与常用路由配置命令详解
  • Windows编程:下载与安装 Visual Studio 2010
  • R语言 文本分析 天龙八部
  • 深度学习 Pytorch 建模可视化工具TensorBoard的安装与使用
  • 【免费】2007-2019年各省科技支出占一般公共预算支出的比重数据
  • 19爬虫:使用playwright登录超级鹰