美文网首页
约束布局常用属性和辅助组件

约束布局常用属性和辅助组件

作者: 镌刻心语 | 来源:发表于2022-11-03 10:30 被阅读0次

一、常用属性

1.相对定位属性:layout_constraint X _to Y Of

一句话描述:当前控件的X边界 - 在 - 目标控件的Y边界
layout_constraintTop_toBottomOf
layout_constraintTop_toTopOf
layout_constraintBottom_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintStart_toEndOf
layout_constraintStart_toStartOf
layout_constraintEnd_toEndOf
layout_constraintEnd_toStartOf
layout_constraintLeft_toLeftOf
layout_constraintLeft_toRightOf
layout_constraintRight_toLeftOf
layout_constraintRight_toRightOf
layout_constraintBaseline_toBaselineOf
一个控件最少需要 两个 相对位置属性 来确定它的具体位置

2.尺寸控制属性:0dp

宽度和高度如果设置为0dp的话,控件就会撑满能够达到的最大宽高。
类似于线性布局里面加了权重的View。

3.居中和偏移属性 :bias

举例
app:layout_constraintHorizontal_bias="0.3"
这边bias=0.3的意思是,左边距离是左右总间距的30%。
假如bias=1的话,控件将紧靠右边界。
假如bias>1的话,控件将超出右边界。
(垂直情况下bias的值是上边距占比)

4.链条布局属性 :Chains

同一个方向(水平或者垂直)上的多个子 View 提供一个类似群组的概念。
该属性添加到群组View的头部子View即可:水平群组,最左边的为头, 垂直群组最上面为头。
layout_constraintHorizontal_chainStyle = "packed"
layout_constraintHorizontal_weight
layout_constraintVertical_chainStyle
layout_constraintVertical_weight
具体的Style值 有三种:
packed
spread
spread_inside

二、辅助控件

1.参照线控件Guideline

参照线就是一个用来对齐其他视图且运行时隐藏的参照视图
app:orientation="vertical"声明参照线是垂直还是水平方向
app:layout_constraintGuide_begin="41dp"表示参照线离父布局ConstraintLayout的起始位置为41dp,再次声明,是start而不是left。
app:layout_constraintGuide_end=""表示相对于右边缘的距离,
对于百分比参照线来说,使用app:layout_constraintGuide_percent="0.5"来描述百分比的偏移量。

2.分组控件:Group

组的作用是可将多个控件一起隐藏或显示。
假如在代码中实例化group控件,然后调用显示隐藏方法。
app:constraint_referenced_ids 里面对应id的view 会一起隐藏或者显示。

3.占位符控件:Placeholder

控件需要移动时的终点
下图例子中Placeholder位于屏幕中心。
<androidx.constraintlayout.widget.Placeholder
android:id="@+id/placeholder"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

按钮点击后:将左上角图片设置到占位符上。
fun click(view: View) {
//设置动画
TransitionManager.beginDelayedTransition(constraintLayout)
//占位填充
placeholder?.setContentId(R.id.logo)
}

4.屏障控件:Barrier

<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="right"
app:constraint_referenced_ids="textView1,textView2"/>

控件A,控件B长度自适应,需要控件C一直在右边,不管A和B谁长谁短 C均在右边。
app:constraint_referenced_ids = "id1,id2 " 对应id的控件都会被屏障控件隔开.
app:barrierDirection="right" 这个属性的意思是:屏障位于指定控件们的右边。

相关文章

  • 约束布局常用属性和辅助组件

    一、常用属性 1.相对定位属性:layout_constraint X _to Y Of 一句话描述:当前控件的X...

  • 从零开始学习flutter -布局

    前言 这篇文章开始主要记录一些常用的组件和组件属性本篇文章主要着重记录一些常用布局 正文 约束布局Constrai...

  • Flutter Layout组件之SizedBox

    一、给子组件附加紧约束 SizedBox是一个单子元素布局组件,有 width,height 两个属性,可以给它的...

  • 约束布局(ConstraintLayout)的常用属性

    1、依赖 2、位置控制的常用属性 3、角度定位 4、边距 5、控件尺寸 6、链 7、屏障 8、组 9、占位符 10...

  • Flutter开发之布局Widget

    一、单子布局组件 单子布局组件的含义是其只有一个子组件,可以通过设置一些属性设置该子组件所在的位置信息等。比较常用...

  • Android ConstraintLayout

    一、ConstraintLayout是一种约束布局,相当于增强版的RelativeLayout常用属性介绍,设置的...

  • Android tools 属性标签简记

    tools 属性的主要分成两个种类,一种是Lint提示辅助,另外一种xml布局辅助。 xml布局辅助属性 Lint...

  • samurai-native CSS属性文档

    通用布局属性 UIButton常用属性 UILabel常用属性 UITextField,UITextView常用属...

  • flutter响应式布局组件wrap

    这个组件常用在响应式布局上,使用灵活多变。可设置属性较多 基础用法的是: 效果是: direction属性默认是A...

  • Android 学习笔记

    一、UI组件 一.布局管理器 1.线形布局 注意:设置属性android:orientation属性,否则有的组件...

网友评论

      本文标题:约束布局常用属性和辅助组件

      本文链接:https://www.haomeiwen.com/subject/gigxtdtx.html