Android ConstraintLayout
来源:互联网 发布:大牌护手霜好 知乎 编辑:程序博客网 时间:2024/05/19 00:15
constraintLayout和RelativeLayout类似,但比RelativeLayout要强大多,它可以有效地解决布局嵌套过多问题,我们平时编写的界面,复杂的布局总会伴随着多层的嵌套,而嵌套越多,程序的性能也就越差;ConstraintLayout则是使用约束的方式来指定各个控件的位置和关系;
2.常用相对属性:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
3.margins属性
- 1
- 2
- 3
- 4
- 5
- 6
4.当前View与另一个View绑定后,另一个View的属性设置为了Gone,则以下属性会生效
- 1
- 2
- 3
- 4
- 5
- 6
5.居中并设置权重,使view居中并且设置权重,同RelativeLayout的center_horizontal/vertical=“true”
设置方法:以横向居中为例(竖向同理):
将ConstraintLayout的子View的属性如下进行设置
- 1
- 2
- 3
- 4
- 5
- 6
- 7
6.设置权重layout_constraintHorizontal_bias(layout_constraintVertical_bias)
例如:下面将会使左侧用30%的偏差,而不是默认的50%,使得左侧将会缩短,与微件倾斜更靠近左侧
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
7.尺寸限制
在ConstraintLayout最小尺寸,被使用ConstraintLayout时,其尺寸设置为WRAP_CONTENT
- android:minWidth 设定的最小宽度为布局
- android:minHeight 设置最低高度布局
注意:
ConstraintLayout 不支持match_parent属性,但支持wrap_content属性。如果你需要用match_parent,将宽度/高度指定为0dp,然后设置left_toleft,right_toRight为parent即可实现横向充满,同理设置竖向的
8.Ratio比例大小属性
You can also define one dimension of a widget as a ratio of the other one. In order to do that, you need to have at least one constrained dimension be set to 0dp (i.e., MATCH_CONSTRAINT), and set the attribute layout_constraintDimentionRatio to a given ratio. For example:
当你的父控件为ConstraintLayout,可以利用这个属性来控制当前View的宽高比。在利用这个属性时,你必须指明一个方向上的大小为0dp,另一个方向可指定为明确的dp值也可以使用wrap_content这样才能够按照比例来为你摆放
例如:“宽度:高度
- 1
- 2
- 3
- 4
也可以这样设置:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
把宽和高设置为0dp,但是通过Top_toTopOf、Bottom_toBottomOf指定高度,通过添加字母W(为约束的宽度)或H (用逗号分隔的前方约束的高度);既是高度已经指定大小,宽度按照对应比例分配大小;
- Android ConstraintLayout
- Android ConstraintLayout
- Android ConstraintLayout
- Android ConstraintLayout
- Android ConstraintLayout
- 了解使用Android ConstraintLayout
- 探索Android ConstraintLayout布局
- 了解使用Android ConstraintLayout
- 了解使用Android ConstraintLayout
- 了解使用Android ConstraintLayout
- 了解使用Android ConstraintLayout
- Android ConstraintLayout详解
- Android 之 ConstraintLayout 眯视
- Android ConstraintLayout详解
- Android ConstraintLayout详解
- Android ConstraintLayout详解
- Android ConstraintLayout 约束布局
- Android _ ConstraintLayout控件
- ONVIF协议网络摄像机(IPC)客户端程序开发(12):读取音视频流
- Nginx的alias的用法及与root的区别
- springboot(十三):springboot小技巧
- 一些在线检测网站打开速度工具大分享
- Mybaits学习之(一)ORM的概念及简单测试
- Android ConstraintLayout
- 第十一周-项目二-操作用邻接表存储的图
- python--字符串操作(删除,替换)
- 第十三周项目二
- (二十五)基础系列 AJAX、JQuery
- ONVIF协议网络摄像机(IPC)客户端程序开发(13):图像抓拍
- 组合模式
- Java web项目如何获取某个文件夹下面的文件路径 绝对路径 ?
- springboot(十四):springboot整合shiro-登录认证和权限管理