constantlayout布局

ConstraintLayout 约束布局,减少布局的层级,优化渲染性能。

1、Circular positioning(圆形定位)
将一个控件的中心以一定的角度和距离约束到另一个控件的中心

	<View android:id="@+id/viewA" ... />
    <View android:id="@+id/viewB" ...
      //引用的控件ID
      app:layout_constraintCircle="@+id/viewA"
      //圆半径
      app:layout_constraintCircleRadius="50dp"
      //偏移圆角度  水平右方向为0逆时针方向旋转
      app:layout_constraintCircleAngle="45" />

2、WRAP_CONTENT : enforcing constraints(强制约束)
控件的宽设置为 WRAP_CONTENT (包裹内容)时,如果实际宽度超过了约束的最大宽度,那么约束会失效。
为了防止约束失效,增加了以下属性:


app:layout_constrainedWidth=”true|false” //默认false
app:layout_constrainedHeight=”true|false” //默认false

约束条件

app:layout_constraintLeft_toRightOf="@+id/bt_1" //控件的左边位于xx控件的右边
app:layout_constraintRight_toRightOf="parent"   //控件的右边位于xx控件的右边

3、MATCH_CONSTRAINT dimensions(填充父窗体约束)

在约束布局中宽高的维度 match_parent 被 0dp 代替,默认生成的大小占所有的可用空间

layout_constraintWidth_min and layout_constraintHeight_min  //设置最小尺寸
layout_constraintWidth_max and layout_constraintHeight_max  //设置最大尺寸
layout_constraintWidth_percent and layout_constraintHeight_percent  //设置相对于父类的百分比

4、goneMargin(隐藏边距)
当约束目标的可见性为View.GONE时,还可以通过以下属性设置不同的边距值:

layout_goneMarginStart
layout_goneMarginEnd
layout_goneMarginLeft
layout_goneMarginTop
layout_goneMarginRight
layout_goneMarginBottom

5、约束之百分比布局
约束布局支持子控件设置宽高比,前提条件是至少需要将宽高中的一个设置为0dp。为了约束一个特定的边,基于另一个边的尺寸,可以预先附加W,或H以逗号隔开。

要求顶部的背景图宽高 16:9 来适配

app:layout_constraintDimensionRatio="H,16:9"

Chains(链)
链使我们能够对一组在水平或竖直方向互相关联的控件的属性进行统一管理。成为链的条件:一组控件它们通过一个双向的约束关系链接起来

      //默认样式
        app:layout_constraintHorizontal_chainStyle="spread"

Guideline

Guideline 与 LinearLayout 类似可以设置水平或垂直方向,android:orientation=“horizontal”,android:orientation=“vertical”,水平方向高度为0,垂直方向宽度为0。Guideline 具有以下的三种定位方式:

layout_constraintGuide_begin 距离父容器起始位置的距离(左侧或顶部)
layout_constraintGuide_end 距离父容器结束位置的距离(右侧或底部)
layout_constraintGuide_percent 距离父容器宽度或高度的百分比

Barrier

在约束布局中,可以使用属性constraint_referenced_ids属性来引用多个带约束的组件,从而将它们看作一个整体,Barrier 的介入可以完成很多其他布局不能完成的功能

 <android.support.constraint.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="right"
        app:constraint_referenced_ids="tv_name,tv_contract"/>

barrierDirection 指定方向,constraint_referenced_ids引用的控件 id(多个id以逗号隔开)。

Group

Group用于控制多个控件的可见性。

来自简书 :https://www.jianshu.com/p/a74557359882

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值