ConstraintLayout属性说明

news2024/9/22 7:41:43

ayout_constraintTop_toTopOf:将某一控件的顶部与另一控件的顶部对齐。

layout_constraintTop_toBottomOf:将某一控件的顶部与另一控件的底部对齐。

layout_constraintBottom_toTopOf:将某一控件的底部与另一控件的顶部对齐。

layout_constraintBottom_toBottomOf:将某一控件的底部与另一控件的底部对齐。

layout_constraintLeft_toLeftOf:将某一控件的左边与另一控件的左边对齐。

layout_constraintLeft_toRightOf:将某一控件的左边与另一控件的右边对齐。

layout_constraintRight_toLeftOf:将某一控件的右边与另一控件的左边对齐。

layout_constraintRight_toRightOf:将某一控件的右边与另一控件的右边对齐。

layout_constraintStart_toEndOf:将某一控件的起始边与另一控件的结束边对齐。

layout_constraintStart_toStartOf:将某一控件的起始边与另一控件的起始边对齐。

layout_constraintEnd_toStartOf:将某一控件的结束边与另一控件的起始边对齐。

layout_constraintEnd_toEndOf:将某一控件的结束边与另一控件的结束边对齐。

layout_constraintBaseline_toBaselineOf:将某一控件的基线与另一控件的基线对齐。

layout_constraintCircle:将两个控件在圆上对齐。

layout_constraintDimensionRatio:设置控件的宽高比。

layout_constraintHorizontal_bias:水平偏向,取值范围0-1,表示在垂直方向上的分布。

layout_constraintVertical_bias:垂直偏向,取值范围0-1,表示在水平方向上的分布。

layout_constraintGuide_begin:指定导航条的起始位置。

layout_constraintGuide_end:指定导航条的结束位置。

layout_constraintGuide_percent:指定导航条相对于父布局的位置百分比。

=====================分割线============================

权重使用方式

                app:layout_constraintHorizontal_widget="1":该控件占比父类控件的竖向权重1(等同LinearLayout的 width="0dp" + widget="1")

        app:layout_constraintVertical_widget="1";该控件占父类控件的横向权重1(等同LinearLayout的height="0dp" + widget="1")

     
                单独使用app:layout_constraintHorizontal_widget="1"仅仅只是确定了控件的宽度权重是1,不能定位控件的位置,所以在使用的时候要注意添加其他属性
                        1 app:layout_constraintLeft_toLeftOf="xxx"控件的起始位置
                        2 app:layout_constraintRight_toRightOf="xxx"控件的结束位置
                        3 android:layout_widget="0dp"控件的宽度设置0

 <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/smart_mode_list"
        android:layout_width="0px"
        android:layout_height="@dimen/rebase_dp_254"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv_smart_mode">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/fl_rest_mode"
            android:layout_width="0px"
            android:layout_height="match_parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintHorizontal_weight="1"
            app:layout_constraintRight_toLeftOf="@id/ivLine"
            tools:ignore="MissingConstraints">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <ImageView
            android:id="@+id/ivLine"
            android:layout_width="@dimen/rebase_dp_3"
            android:layout_height="@dimen/rebase_dp_134"
            android:src="@drawable/vertical_line"
            app:layout_constraintLeft_toRightOf="@id/fl_rest_mode"
            app:layout_constraintRight_toRightOf="@id/fl_projection_mode"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="MissingConstraints" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/fl_projection_mode"
            android:layout_width="0px"
            android:layout_height="match_parent"
            app:layout_constraintHorizontal_weight="1"
            app:layout_constraintLeft_toRightOf="@id/ivLine"
            app:layout_constraintRight_toRightOf="parent"
            tools:ignore="MissingConstraints">

            <TextView
                android:id="@+id/tv_projection_mode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

        

  居中方式
 
 <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="math_parent"
        android:layout_height="math_parent">

        <!--类似LinearLayout布局的横向水平居中-->
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            app:layout_constraintTop_toTop="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <!--类似LinearLayout布局的横向水平居中-->
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"/>

 </androidx.constraintlayout.widget.ConstraintLayout>
   ConstraintLayout中有两个控件居中显示,间隔10dp      

               竖向链式布局app:layout_constraintHorizontal_chainStyle="packed"

               横向链式布局app:layout_constraintVertical_chainStyle="packed"

                chainStyle有三种:

                        spread:(默认)紧促的,

                

                        spread_inside

                

                        packed

                

                 具体xml布局

 <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="0px"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHorizontal_weight="1"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@id/ivLine"
            app:layout_constraintTop_toTopOf="parent"
            tools:ignore="MissingConstraints">


            //在这里使用chainStyle属性
            <ImageView
                android:layout_width="@dimen/rebase_dp_80"
                android:layout_height="@dimen/rebase_dp_80"
                android:src="@drawable/pet_mode_img"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@id/tv_rest_mode"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintHorizontal_chainStyle="packed"
                tools:ignore="ContentDescription" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="小爪爪"
                android:textColor="@color/text_color_AC42D5"
                android:textSize="@dimen/rebase_sp_40"
                android:maxLines="1"
                android:layout_marginLeft="@dimen/rebase_dp_20"
                app:layout_constraintBottom_toBottomOf="@id/iv_rest_mode"
                app:layout_constraintLeft_toRightOf="@id/iv_rest_mode"
                app:layout_constraintTop_toTopOf="@id/iv_rest_mode"
                app:layout_constraintRight_toRightOf="parent"
                tools:ignore="SpUsage" />

        </androidx.constraintlayout.widget.ConstraintLayout>

  总结:ConstraintLayout使用方式需要考虑周全,能加上的就要加上。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1943375.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

3GPP R18 Multi-USIM是怎么回事?(四)

前几篇主要是MUSIM feature NAS 部分内容的总结,这篇开始看RRC部分相关的内容,由于RRC部分内容过长,也分成了2篇。这篇就着重看下musim gap以及RRC触发UE离开RRC Connected mode相关的内容,直入正题, 上面的内容在overview中有提到,对应的是如下38.300中的描述。 处于网络…

【Node.js基础02】fs、path模块

目录 一&#xff1a;fs模块-读写文件 1 加载fs模块对象 2 读制定文件内容文件 3 向文件中写入内容 二&#xff1a;path模块-路径处理 1 问题引入 2 __dirname内置变量 使用方法 一&#xff1a;fs模块-读写文件 fs模块封装了与本机文件系统交互方法和属性 1 加载fs模块…

Win11 改造

记录一些安装 win11 系统之后&#xff0c;对使用不习惯的地方&#xff0c;进行的个人改造 右键菜单 Hiyoung006/Win11Useable: 将Win11右键菜单及资源管理器恢复为Win10样式的脚本 切换到旧版右键菜单&#xff1a; reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34…

Chapter18 基于物理的渲染——Shader入门精要学习

Chapter18 基于物理的渲染 一、PBS理论和数学基础1.光是什么微表面模型 2.渲染方程3.精确光源4.双向反射分布函数 BRDF5.漫反射项&#xff08;Lambert 模型&#xff09;Lambertian BRDF为&#xff1a;Disney BRDF中漫反射项 6.高光反射项微面元理论BRDF的高光反射项①菲涅尔反射…

LabVIEW和IQ测试仪进行WiFi测试

介绍一个使用LabVIEW和LitePoint IQxel-MW IQ测试仪进行WiFi测试的系统。包括具体的硬件型号、如何实现通讯、开发中需要注意的事项以及实现的功能。 使用的硬件​ IQ测试仪型号: LitePoint IQxel-MW 电脑: 配置高效的台式机或笔记本电脑 路由器: 支持802.11ax (Wi-Fi 6) 的…

便携气象站:科技助力气象观测

在科技飞速发展的今天&#xff0c;便携气象站以其轻便、高效、全面的特点&#xff0c;正逐渐改变着气象观测的传统模式。这款小巧而强大的设备&#xff0c;不仅为气象学研究和气象灾害预警提供了有力支持&#xff0c;更为户外活动、农业生产等领域带来了诸多便利。 便携气象站是…

遗传算法模型Python代码——用Python实现遗传算法案例

一、遗传算法概述 1.1适用范围 遗传算法&#xff08;Genetic Algorithm, GA&#xff09;是一种启发式搜索算法&#xff0c;广泛应用于以下领域&#xff1a; 优化问题&#xff1a;如函数优化、路径规划、资源分配等。机器学习&#xff1a;用于特征选择、超参数优化等。经济与…

服务器系统盘存储不够,添加数据盘并挂载(阿里云)

目录 1.获取数据盘设备名称 2.为数据盘创建分区 3.为分区创建文件系统 4.配置开机自动挂载分区 阿里云数据盘挂载说明链接&#xff1a;在Linux系统中初始化小于等于2 TiB的数据盘_云服务器 ECS(ECS)-阿里云帮助中心 1.获取数据盘设备名称 sudo fdisk -lu 运行结果如下所示…

解决 elementUI 组件在 WebStorm 中显示为未知标签的问题

解决 elementUI 组件在 WebStorm 中显示为未知标签的问题 一、问题 自从转到 ts 之后&#xff0c;编辑器就一直提示用到的 elementUI 标签未知&#xff0c;一直显示一溜黄色警示&#xff0c;很烦&#xff1a; 二、解决 把它改成大写就可以了。 如下&#xff1a; 把整个项目…

【C++】学习笔记——哈希_2

文章目录 十八、哈希3. 实现哈希表哈希表的存储节点哈希函数哈希表的定义哈希表的插入哈希表的查找哈希表的删除测试函数完整代码结果 未完待续 十八、哈希 3. 实现哈希表 哈希表的实现方法有蛮多种&#xff0c;这里我们选一个比较经典的开散列法来实现哈希表。由于STL库里的…

使用PicGo操作gitee图床(及web端html不能访问图片的解决办法)

1.新建仓库 2.输入仓库名称,也就是图床名称,必须设置开源可见 也可以在创建仓库后,点击管理->基本信息->是否开源进行设置 鼠标悬浮到右上角头像->设置 点击私人令牌 点击生成新令牌,填写描述,直接点提交即可 点击提交后输入登录密码会生成一个token秘钥,如下,这个…

新版本异次元荔枝V4自动发卡系统源码

新版本异次元荔枝V4自动发卡系统源码&#xff0c;增加主站货源系统&#xff0c;支持分站自定义支付接口&#xff0c;目前插件大部分免费&#xff0c;UI页面全面更新&#xff0c;分站可支持对接其他分站产品&#xff0c;分站客服可自定义&#xff0c;支持限定优惠。 源码下载&a…

matlab--legend利用for循环添加图例

第一种方法 %% 第一种方法 R 1:4; THETA1 atand(R./1.8); legend_name {}; for i 1:4THETA atand(R(i)./1.8);intTheta floor(THETA);R_THERA 1.8 - (R(i)./tand(intTheta-10:intTheta10));R_THERA1 1.8 - (R(i)/tand(intTheta));plot(R_THERA);grid on;hold onlegend…

Git之repo sync -c与repo sync -dc用法区别(四十八)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 优质专栏&#xff1a;多媒…

了解Linux中的shell脚本

目录 1、什么是shell 2、编写第一个shell文件 3、shell的权限 4、变量 5、 shell传递参数 6、shell数组 7、shell基本运算符 7.1 算术运算符 7.2 关系运算符 7.3 布尔运算符 7.4 逻辑运算符 7.5 字符串运算符 8、控制语句 8.1 if 8.2 for 8.3 while语句 9、其他 1、…

C++~~string模拟实现(3)

目录 1.传统写法和现代写法 2.对于流提取的优化 3.简单机制了解 4.string类的几个构造函数总结 4.1基本用法 4.2两个赋值方式 4.3拷贝构造 4.4获取字符 4.5一个容易混淆的对比 4.6创建对象 1.传统写法和现代写法 &#xff08;1&#xff09;上面的代码里面的左边部分是…

排序---归并排序

归并排序 一、定义二、实现原理三、代码实现 一、定义 归并排序&#xff08;MERGE-SORT&#xff09;是建立在归并操作上的一种有效的排序算法,该算法是采用分治法&#xff08;Divide andConquer&#xff09;的一个非常典型的应用。将已有序的子序列合并&#xff0c;得到完全有…

ES中聚合查询之date_histogram查询出现key_as_string 和 key含义

ES中聚合查询之date_histogram查询出现key_as_string 和 key含义 DSL语句 #实例 GET /capture_features_202407/_search {"query": {"bool": {"must": [{"terms": {"plateNo": ["汉A00001"]}},{"range&quo…

【C++】——初识模版

文章目录 前言函数模版函数模版的原理函数模版的实例化 类模版类模版的实例化 前言 当我们使用一个通用的函数&#xff1a; //为每一个类型都编写一个重载版本 void Swap(int& left, int& right) {int temp left;left right;right temp; } void Swap(double& …

Java实现七大排序(一)

目录 一.插入排序 1.直接插入排序 2.希尔排序 二.选择排序 1.选择排序 2.堆排序 三.总结 一.插入排序 1.直接插入排序 直接插入排序的原理与线下玩扑克牌类似。我们拿到一张牌后要排序&#xff0c;方法就是一张一张对。直接插入排序也是这样的&#xff0c;我们得到一张…