ConstraintLayout常用属性

Android ConstraintLayout 约束布局 1 目前已经更新的部分资料:《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!扫码获取!!(备注:Android)**[外链图片转存中…(img-542Cqt8P-1713000810822)][外链图片转存中…(img-wWm5ANmB-1713000810823)][外链图片转存中…(img-lKcgUppI-1713000810823)]《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取! 阅读详情

ConstraintLayout就是常说的约束性布局,所谓约束性就是通过一些特定“条件”来控制View的位置。既然是约束View,那么就必须有一个“相对点”,就是不变的,这样我们才能进行约束,个人认为ConstraintLayout的这个“相对点”就是父布局(ConstraintLayout)。

就像我们在一个空房子里面一样,怎么确定你站在那个位置?我们可以说在左上角、右下角、横向中间偏下多少米等这样的术语来确定自己的位置。ConstraintLayout也是如此。

要确定ConstraintLayout里面View的位置,可以设置在父布局的左上角,那么这个左上角怎么指定呢?首先要知道是那个父布局(ConstraintLayout),通常我们会给父布局设置一个id,在Constraintlayout系统已经帮我们设置了父布局的id,就是parent。但是我们也可以自己设置,多此一举没必要。明白这一点我们就开始看一下怎么确定View在房间的那个位置。

1.重叠位置属性
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"

这里所说的重叠是在不设置margin的前提下,也就是当前View的上下左右都和目标View重叠,相当于常用布局RelativeLayout的功能。

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="左上角"
    android:textSize="30dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="右下角"
    android:textSize="30dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent" />
2.基线对齐
app:layout_constraintBaseline_toBaselineOf="@id/tv_2"

在做涉及数字显示的时候经常遇到,数字和其前面/后面的文件字体不一样大,视觉小姐姐要求文本“底部”对齐,当我们按照自己觉得正确的方式设置后,小姐姐总是不满意,这就涉及到文本基线的问题了。在之前我们需要自己重写TextView去处理这个“bug”,有了ConstraintLayout就用我们自己处理了。

通过设置Guideline预览看到数字和文字是内容在一个水平线上,完美达到小姐姐的要求。

TextView
    android:id="@+id/tv_8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="金额:"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="100dp"
    app:layout_constraintLeft_toLeftOf="parent" />

<TextView
    android:id="@+id/tv_9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="889.98"
    android:textSize="50dp"
    app:layout_constraintLeft_toRightOf="@id/tv_8"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBaseline_toBaselineOf="@id/tv_8"/>

<TextView
    android:id="@+id/tv_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="8.5"
    android:textSize="50dp"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="200dp"
    app:layout_constraintLeft_toLeftOf="parent" />

<TextView
    android:id="@+id/tv_2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="折"
    app:layout_constraintLeft_toRightOf="@id/tv_1"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBaseline_toBaselineOf="@id/tv_1"/>

<androidx.constraintlayout.widget.Guideline
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.16" />

<androidx.constraintlayout.widget.Guideline
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.35" />
3.相对位置属性
app:layout_constraintLeft_toRightOf="@id/tv_3"
app:layout_constraintRight_toLeftOf="@id/tv_3"
app:layout_constraintTop_toBottomOf="@id/tv_3"
app:layout_constraintBottom_toTopOf="@id/tv_3"
app:layout_constraintStart_toEndOf="@id/cl_3"
app:layout_constraintEnd_toStartOf="@id/cl_3"

所谓相对位置就是当前View在目标View的上下左右方向位置,相当于LinearLayout的功能,但是功能比其更强大。

<TextView
    android:id="@+id/tv_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="左上角"
    android:textSize="30dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="在tv_1右下角"
    android:textSize="30dp"
    app:layout_constraintTop_toBottomOf="@id/tv_1"
    app:layout_constraintLeft_toRightOf="@id/tv_1" />
4.View居中

在ConstraintLayout中没有LinearLayout中的gravity="center_vertical | center_horizontal | center"这样的控制内部View居中属性,也没有RelativeLayout中的layout_centerHorizontal="true",layout_centerVertical="true",layout_centerInParent="true"控制View自身内部居中属性。

在ConstraintLayou中2个相对方向的重叠属性就是居中,例如左右居中可以这样设置:layout_constraintLeft_toLeftOf="parent",同时layout_constraintRight_toRightOf="parent",当前View左侧和右侧在父布局的左侧和右侧,那就是居中,相当于你的位置距离房子的左侧和右侧一样的距离,那这样你就是左右居中的。同样上下居中需要同时设置layout_constraintBottom_toBottomOf="parent"和layout_constraintTop_toTopOf="parent"。

<TextView
    android:background="@color/colorPrimary"
    android:id="@+id/tv_1"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="水平居中"
    android:textSize="30dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />

<TextView
    android:background="@color/colorPrimary"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="垂直居中"
    android:textSize="30dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
5.间距goneMargin
app:layout_goneMarginStart="10dp"
app:layout_goneMarginEnd="10dp"
app:alayout_goneMarginLeft="10dp"
app:layout_goneMarginTop="10dp"
app:layout_goneMarginRight="10dp"
app:layout_goneMarginBottom="10dp"

实际开发中会遇到当前View在目标View的右侧并存在margin间距,当目标View隐藏之后,这个margin会根据目标View左侧的View为准,左侧没有其他View就会以父布局为准。但是这不一定是我们想要的效果,我们想要当目标View隐藏之后重新设置一个间距,也就是目标View显示和隐藏2个状态下都设置好间距,这个时候goneMargin就派上用场了。

<TextView
    android:id="@+id/tv_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="左上角"
    android:textSize="30dp"
    android:visibility="visible"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="在tv_1右边"
    android:textSize="30dp"
    android:layout_marginLeft="20dp"
    app:layout_goneMarginLeft="100dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toRightOf="@id/tv_1" />
6.View居中偏移量
app:layout_constraintVertical_bias="0.3" 0~1
app:layout_constraintHorizontal_bias="0.9" 0~1

ConstraintLayout的强大不止如此,在设置居中后,还可以通过设置属性layout_constraintHorizontal_bias="0.9"或者layout_constraintVertical_bias="0.3"修改当前View距离两个边缘的比例。

<TextView
    android:id="@+id/tv_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="水平居中"
    android:textSize="30dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintHorizontal_bias="0.3"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:text="垂直居中"
    android:textSize="30dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.3"/>
7.目标View周围扇形分布
app:layout_constraintCircle="@id/tv_4" 圆心点View
app:layout_constraintCircleAngle="70" 偏移角度(正上方为0度)
app:layout_constraintCircleRadius="100dp" 圆半径
<TextView
    android:id="@+id/tv_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="•"
    android:textSize="30dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:text="12"
    android:textSize="30dp"
    app:layout_constraintCircle="@id/tv_1"
    app:layout_constraintCircleAngle="0"
    app:layout_constraintCircleRadius="100dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:text="3"
    android:textSize="30dp"
    app:layout_constraintCircle="@id/tv_1"
    app:layout_constraintCircleAngle="90"
    app:layout_constraintCircleRadius="100dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:text="6"
    android:textSize="30dp"
    app:layout_constraintCircle="@id/tv_1"
    app:layout_constraintCircleAngle="180"
    app:layout_constraintCircleRadius="100dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:text="9"
    android:textSize="30dp"
    app:layout_constraintCircle="@id/tv_1"
    app:layout_constraintCircleAngle="270"
    app:layout_constraintCircleRadius="100dp" />
8.百分比效果
android:layout_width="0dp"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.5" 设置百分比,默认是1(100%)

android:layout_height="0dp"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.5" 设置百分比,默认是1(100%)
<TextView
    android:id="@+id/tv_1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintWidth_default="percent"
    app:layout_constraintWidth_percent="0.5"
    android:background="@color/colorPrimary"
    android:text="水平50%"
    android:textSize="30dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintHeight_default="percent"
    app:layout_constraintHeight_percent="0.5"
    android:background="@color/colorPrimary"
    android:text="垂直50%"
    android:textSize="30dp" />
9.设置宽高比
app:layout_constraintDimensionRatio="1:2"
app:layout_constraintDimensionRatio="H,16:2"
app:layout_constraintDimensionRatio="W,2:16"

当一直View的宽/高即:layout_height="0dp"/layout_width="0dp",其高/宽是按照某一个比例进行显示的,那么就可以使用此属性进行实现。

如果宽和高都无法确定即:layout_width="0dp"和layout_height="0dp",可以根据父布局的宽/高设置比例。layout_constraintDimensionRatio="H,16:2"和layout_constraintDimensionRatio="W,2:16"有着同样的效果,只是书写方式不同而已,而且里面的H和W可以换成小写字母h和w。

<TextView
    android:id="@+id/tv_1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:background="@color/colorPrimary"
    app:layout_constraintDimensionRatio="1:3"
    android:text="宽已知1:3"
    android:textSize="30dp" />

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintRight_toRightOf="parent"
    android:background="@color/colorPrimary"
    android:text="高已知4:1"
    android:textSize="30dp"
    app:layout_constraintDimensionRatio="4:1"/>

至于layout_width="0dp"和layout_height="0dp"的情况个人感觉不是很好理解,要想有效果必须设置相对2个方向的属性:layout_constraintLeft_toLeftOf="parent"和layout_constraintRight_toRightOf="parent",或者layout_constraintTop_toTopOf="parent"和layout_constraintBottom_toBottomOf="parent",否则没有效果,即便这样同样的layout_constraintDimensionRatio="W,1:1"属性,设置不同方向之后效果也会不同,建议根据自己实际情况自己测试一下,这种宽高都不确定的情况基本也不会有。

10.链chain
 layout_constraintHorizontal_chainStyle="packed | spread | spread_inside"
 layout_constraintHorizontal_weight="0.1"

上图为官网图,使用此属性的前提是有多个View有所依赖关联,例如下面布局:

<TextView
    android:id="@+id/tv_5"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="450dp"
    android:background="@color/colorAccent"
    android:text="左边"
    app:layout_constraintHorizontal_chainStyle="spread_inside"
    app:layout_constraintHorizontal_weight="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@id/tv_6"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/tv_6"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="450dp"
    android:background="@color/colorPrimaryDark"
    android:text="中间"
    app:layout_constraintHorizontal_weight="1"
    app:layout_constraintLeft_toRightOf="@id/tv_5"
    app:layout_constraintRight_toLeftOf="@id/tv_7"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/tv_7"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="450dp"
    android:background="@color/colorAccent"
    android:text="右边"
    app:layout_constraintHorizontal_weight="1"
    app:layout_constraintLeft_toRightOf="@id/tv_6"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

1.

android:layout_width="0dp"
layout_constraintHorizontal_chainStyle="packed"
layout_constraintHorizontal_weight="0.1"

packed/spread/spread_inside都是根据layout_constraintHorizontal_weight比例设置。

2.

android:layout_width="固定值"
layout_constraintHorizontal_chainStyle="packed"
layout_constraintHorizontal_weight 失效

View紧挨在中间,保留各自的原始width,两边剩余间距平分。

3.

android:layout_width="固定值"
layout_constraintHorizontal_chainStyle="spread"
layout_constraintHorizontal_weight 失效

View保留各自的原始width,两边剩余间距以及两两之间间距平分。

4.

android:layout_width="固定值"
layout_constraintHorizontal_chainStyle="spread_inside"
layout_constraintHorizontal_weight 失效

View保留各自的原始width,两边(上下)在端点,中间的View平分,两两之间间距平分。

5.

android:layout_width="固定值"
layout_constraintHorizontal_chainStyle="packed"
layout_constraintHorizontal_weight 失效
layout_constraintHorizontal_bias="0.3"

View保留各自的原始width,所有View紧挨在一起,左右间距按照比例分配。和情况2相似,两边间距是按照比例。(注意:layout_constraintHorizontal_bias="0.3"只在第一个/最左边的View上生效)

11.Group组
app:constraint_referenced_ids="tv_a, tv_b, tv_c" 

在实际开发中会经常根据条件设置View的GONE和VISIBLE,单个View只需要设置一个就可以,如果是需要操作多个View的GONE或者VISIBLE,就需要为每一个View设置,这样代码就会很多,而且可能这些View没有其他任何操作,引入没有必要的View。

有没有办法可以统一设置呢?当然有,在不采用ConstraintLayou时,我们可以把相关View放在一个ViewGroup,前提是这几个View存在某种关联允许放在一个ViewGroup可以完成实际的效果,但现实这个样的情况很少,基本都是没有关联,那就无法实现统一实现GONE或者VISIBLE。

在使用ConstraintLayout之后就可以使用Group来实现统一控制一组View的GONE或者VISIBLE了,而且无须这些View存在某种关联。

<androidx.constraintlayout.widget.Group
    android:id="@+id/group"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:constraint_referenced_ids="tv_a, tv_b, tv_c" />

代码中设置就会把3个View隐藏。

group.visibility = GONE
12.屏障Barrier

在开发中我们经常遇到类似的布局,右边的图片在2个文本内容的右侧,不管“标题”和“描述”宽度多少。那么这种情况就采用LinearLayout嵌套的方式,这样就会出现层级过多;RelativeLayout也可以实现,但是也存在问题:我们设置图片在“标题”View的右侧并设置间距,当“标题”内容过短,“描述”内容过长的时候就会出现图片遮挡“描述”的情况。

ConstraintLayout就给我提供了一个好的办法:在2个文本右侧设置一个屏障,然后通过设置图片在屏障的右侧并设置间距就可以了,这样无论2个文本长度如何都不会影响显示。

<TextView
    android:id="@+id/tv_8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="这个标题有点长长长长长长长长呀"
    app:layout_constraintLeft_toLeftOf="parent" />

<TextView
    android:id="@+id/tv_9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="描述"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@id/tv_8" />

<ImageView
    android:id="@+id/tv_10"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginLeft="20dp"
    android:src="@mipmap/ic_launcher"
    android:background="@color/colorPrimary"
    app:layout_constraintStart_toEndOf="@id/barrier" />

<androidx.constraintlayout.widget.Barrier
    android:id="@+id/barrier"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:barrierDirection="end"
    app:constraint_referenced_ids="tv_8,tv_9" />
13.辅助线Guideline

在实际开发中,经常遇到在布局中2个距离较远的View是否在一个水平线或者垂直线上而话费较多时间去判断,毕竟肉眼看到的存在视觉上失误,这个时候Guideline就会帮到我们,此View只会在Xml布局预览中显示,运行之后是不存在的,辅助我们判断View是否在一个水平或者垂直线上。

<androidx.constraintlayout.widget.Guideline
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.4" />

<androidx.constraintlayout.widget.Guideline
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.4" />
14.绝对位置
app:layout_editor_absoluteX="300dp"
app:layout_editor_absoluteY="400dp"

设置目标View在布局中的绝对位置,运行之后失效。实际中暂无发现实际作用

注意点

margin属性只有在设置了1和2情况中的属性时才会有效,例如:设置了属性app:layout_constraintTop_toTopOf="parent"或者app:layout_constraintTop_toBottomOf="@id/tv_3",android:layout_marginTop="30dp"才会有效果。其他margin属性也是同理。

Android ConstraintLayout 详解(背景和原理、概述和特性以及用法、常用属性和使用场景等等) ConstraintLayout 是 Android Jetpack 库提供的强大布局管理器,它允许您在 Android 应用中创建复杂的布局,同时保持视图层次的扁平化。它设计灵活、高效且易于使用。 阅读详情

相关推荐

GD32F4系列定时器正交译码器实战:用TIMER1读取旋转编码器信号(附完整代码)

本文详细介绍了GD32F4系列定时器正交译码器的实战应用,重点讲解如何使用TIMER1模块高效读取旋转编码器信号。内容涵盖硬件连接、定时器配置、方向判断与速度计算等关键环节,并提供了完整的代码实现和优化建议,帮助开发者快速掌握GD32微控制器在工业控制和消费电子领域的编码器接口设计。

weixin_29169505的博客 204

基础布局之ConstraintLayout约束布局

基础布局之ConstraintLayout约束布局

似霰的博客 7094

ESP-01S使用micropython,利用Thonny烧写固件

在家舒服的太久了,想学习点新的东西,这次看上了ESP8266系列的联网设备,想自己做点小玩意出来耍耍,下面跟我一起来学习吧。本篇主要记录固件的烧写及测试。Thonny下载链接不算难,但是网上资源较少。也是提醒自己不要忘记这个步骤,记录一下,也分享给和我一样开始接触的小伙伴,加油加油,万事开头难。

weixin_43422072的博客 1698

ConstraintLayout 终极秘籍(上)

ConstraintLayout 终极秘籍(上) 时间 2017-02-25 12:25:49  云在千峰 原文  http://blog.chengyunfeng.com/?p=1030 主题 安卓开发 ConstraintLayout 终于 正式发布 1.0 版本 了,是时候来详细介绍下这个 Android 布局的终极武器了。 为何需要 Constrain

fallfollowernolisten的博客 5954

5G NR上行控制信道PUCCH

一、PUCCH概述 PUCCH用于承载上行控制信息,相比LTE,NR PUCCH支持5种不同的格式,按照时域上所占用的符号数量可以分为短格式和长格式两种,如下表所示,短格式占用1-2个符号,可以承载1-2bit信息,长格式占用4-14个符号,可承载大于2bit的信息。NR引入短格式PUCCH的目的是可以缩短HARQ-ACK反馈的时延,长格式仍然是考虑到持续时间长可以保证覆盖。 NR中,考虑到系...

一个关于5G NR的博客^^ 3万+

告别里程焦虑:手把手教你用MATLAB/Simulink仿真电动车AMT换挡规律(附代码)

本文详细介绍了如何使用MATLAB/Simulink仿真电动车AMT换挡规律,帮助解决里程焦虑问题。通过搭建完整的仿真系统,包括电机MAP图处理、Stateflow逻辑实现和动力性与经济性换挡曲线生成,优化电动车换挡策略以提升续航与性能。附带的代码示例和实用技巧使开发者能够快速上手并验证仿真结果。

weixin_26757925的博客 308

Android Studio:ConstraintLayout的常用属性详解

约束布局ConstraintLayout 是一个ViewGroup,可以在Api9以上的Android系统使用它,它的出现主要是为了解决布局嵌套过多的问题,以灵活的方式定位和调整小部件。从 Android Studio 2.3 起,官方的模板默认使用 ConstraintLayout

star_nwe的博客 4293

从零构建:STM32与EC800 4G模块的工业物联网数据透传实战

本文详细介绍了如何从零构建STM32与EC800 4G模块的工业物联网数据透传系统。内容涵盖硬件选型、抗干扰电路设计、AT指令稳定性优化、网络连接管理、可靠数据透传协议以及低功耗策略,为开发者提供了一套可直接应用于工业场景的完整实战方案。

uran的专栏 1022

Android详解——ConstraintLayout约束布局

ConstraintLayout继承自ViewGroup,允许用户以更加灵活的方式在布局中设置控件的位置和尺寸(ConstraintLayout在API>9可用)。ConstraintLayout采用方向约束的方式对控件进行定位,至少要保证水平和垂直方向都至少有一个约束才能确定控件的位置。相对位置边距中心位置圆形位置可见性尺寸约束链式布局虚拟辅助控件优化器记住,依赖关系中不能有循环依赖关系。

闲暇部落 5367

STC8H8K64U ADC采样实战:从蜂鸣器控制到电压测量(附完整代码)

本文以STC8H8K64U单片机为核心,通过两个实战案例详细讲解ADC采样的应用。首先介绍如何利用ADC采样值动态控制蜂鸣器响度,实现模拟PWM效果;其次深入探讨高精度外部电压测量的方法,包括硬件连接、两点校准技巧以及软件滤波,旨在帮助开发者从理论到实践全面掌握ADC功能。

weixin_29159441的博客 563

CST高阶技巧:用周期性边界快速仿真共面波导色散特性(含JDM求解器优化)

本文详细介绍了在CST仿真软件中,利用周期性边界条件结合JDM本征模求解器,高效分析共面波导色散特性的高阶技巧。该方法通过仿真一个单元胞而非整条传输线,大幅提升计算效率,并提供了从建模、边界设置、求解器优化到后处理的完整工作流程,是高频电路设计的实用指南。

weixin_29280219的博客 405

Android约束布局(ConstraintLayout)常用属性

本文介绍了Android ConstraintLayout常用属性的应用案例,属性组合使用可以构建灵活且高性能的Android界面。

Meteors.的博客 582

【CAN总线测试】——通讯相关诊断测试

本章主要介绍通讯相关诊断测试用例设计

LOVE135149的博客 1828

ConstraintLayout不常用的属性

Chains 链使我们能够对一组在水平或竖直方向互相关联的控件的属性进行统一管理。 成为链条的条件: 一组控件之间通过一个双向的约束关系链接起来,并且链的属性由一条链的头结点控制,如下图所示: 布局如下: &amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt; &amp;lt;android.support.constraint.Constrain

热爱不止,前行不息 2445

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

ConstraintLayout常用属性记录

ConstraintLayout控件很强大,现在基本上写布局都是用它写的,简单记录下几个常用api 相对定位 layout_constraintLeft_toLeftOf 我的左侧与你的左侧对齐 layout_constraintLeft_toRightOf 我的左侧与你的右侧对齐 layout_constraintRight_toLeftOf 我的右侧与你的左侧对齐 layout_constraintRight_toRightOf 我的右侧与你的右侧对齐 layout_constraintTop_t

zhangrgg的博客 489

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

ConstraintLayout 常用属性

当布局嵌套深入比较深的时候,往往会伴随着一些性能问题。ConstraintLayout可以解决一些嵌套的问题,使用上和RelativeLayout 类似    相关约束: 1. app:layout_constraintLeft_toLeftOf="parent" 从字面上看,指的是让该控件的左侧与父布局对齐,当我们希望控件A与控件B左侧对齐时,就可以使用该属性。 app:la...

Jason_HD的博客 888

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Android ConstraintLayout约束布局 常用属性和辅助控件

1.相对定位属性:layout_constraintX_toYOf 一句话描述:当前控件的X边界 - 在 -目标控件的Y边界 layout_constraintTop_toBottomOf layout_constraintTop_toTopOf layout_constraintBottom_toBottomOf layout_constraintBottom_toTopOf layout_constraintStart_toEndOf ...

赵星海 1489

android constraintlayout垂直居中_2020 年Android入门教程之ConstraintLayout布局 005

今天来学习下ConstraintLayout这个布局。目前在最新版本的Android Studio 中新创建一个项目之后。默认创建的activity布局中使用的根布局为ConstraintLayout。ConstraintLayout是什么,在我看来,它就是RelativeLayout的升级版本。今天我们就来学习下这个布局,但是我们作为入门教程,不会很深入的讲解,这个布局内容还是蛮多的。首先,更改...

weixin_39674978的博客 410

ConstraintLayout的使用介绍,持续更新

ConstraintLayout,即约束布局, 已经推出很久了。布局方式与RelativeLayout有点类似,但可以说是RelativeLayout的升级版,ConstraintLayout可以完全代替其他布局, 减少布局的层级, 优化渲染性能。在新版Android Studio中, ConstraintLayout已替代RelativeLayout, 成为HelloWorld项目的...

rhino 7399

Android 的 ConstraintLayout 布局使用

加依赖:确保里有。定根布局:根标签用。放视图:把ButtonTextView等放进去。添约束(最关键!:为每个视图的水平方向和垂直方向至少各加一个约束。水平方向:约束Start或End。垂直方向:约束Top或Bottom。常用目标parent(父布局)或其他视图的id。打开 Android Studio 的布局编辑器,直接拖拽控件,观察它自动生成的约束代码,这是最快的学习途径!场景推荐选择理由新项目开发性能好、功能强、现代标准复杂界面减少嵌套、响应式支持好简单相对定位代码更简洁直观。

m0_61945436的博客 1314

约束布局ConstraintLayout

1、约束布局的出现背景 随着Android手机的普遍,APP已经成为我们日常生活中必不可少的部分,但随着APP不断的更新细化,布局也越来越复杂,更多层次的嵌套,已经成为影响APP性能的一个重要环节,也是我们在开发中不断优化的部分。Google也在为提高APP性能而不断改变着,因此在Android studio的2.3版本新建的Module中默认的布局就是 ConstraintLayout。 C...

LPL0129的博客 2011

Android ConstraintLayout 约束布局(一)

世上无难事只怕有心人 前言在Android开发中最常见的问题,除了报空指针,那就是屏幕的适配问题,针对空指针的问题,在另一篇博客中有提到过Android的新的官方开发语言Kotin(点击查看),可以完美地解决这个问题,在这里不再过多地解释,而接下来,所介绍的针对屏幕界面适配和编写的问题,Android官方提供了一个新的布局(也不算是新的,在Android studio2.3.3就已经出现)——Con

常利兵的博客 626

Android ConstraintLayout

constraintLayout和RelativeLayout类似,但比RelativeLayout要强大多,它可以有效地解决布局嵌套过多问题,我们平时编写的界面,复杂的布局总会伴随着多层的嵌套,而嵌套越多,程序的性能也就越差;ConstraintLayout则是使用约束的方式来指定各个控件的位置和关系; 2.常用相对属性: layout_constraintTop_toTopOf

Target的博客 439

LinearLayout、RelativeLayout、ConstraintLayout、FrameLayout和GridLayout这几个常用布局文件的使用方法和代码示例

通过以上代码示例,你可以了解到LinearLayout、RelativeLayout、ConstraintLayout、FrameLayout和GridLayout的基本使用方法,以及如何在布局文件中定义和排列子视图。- 使用方法:LinearLayout通过水平(horizontal)或垂直(vertical)方式排列子视图。- 使用方法:ConstraintLayout基于视图之间的约束关系来排列子视图。- 使用方法:FrameLayout允许将子视图叠放在一起,后添加的视图会覆盖之前的视图。

程序员大爷 978

ConstraintLayout支持的大部分属性

这些属性涵盖了ConstraintLayout支持的大部分属性。在使用ConstraintLayout布局时,掌握这些属性非常重要,并且要根据实际需求选取适合的属性进行布局

qq_35399803的博客 472
上一篇: Android Kotlin中apply、also、let、run、with的使用
下一篇: Javapoet实现编译期创建文件的一些注意点
qq_24293111
博客等级 码龄12年 1粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址