ConstraintLayout

一、概述

    在编写andorid界面时,总喜欢用LinearLayout。每次android stdio 总是自动生成constraintLayout布局。于是就想既然官方推荐,那么必然有其强大的功能。于是开始了学习。constraintLayout 可以理解为对widget在指定的方向上用力拉,哪个方向上有力widget就往哪个方向移动,如果相对的两个方向都有力并且一样大那么就居中,如果不一样大就向力大的那个偏移。

二、用法

            属性列表及解释:
layout_constraintLeft_toLeftOf =“@id/widgetId”:约束widget的左边,在widgetId的左边用力拉widget.
layout_constraintLeft_toRightOf
layout_constraintRight_toLeftOf
layout_constraintRight_toRightOf
layout_constraintTop_toTopOf
layout_constraintTop_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintBottom_toBottomOf

# 与left,right类似
layout_constraintStart_toEndOf
layout_constraintStart_toStartOf
layout_constraintEnd_toStartOf
layout_constraintEnd_toEndOf

# margin不需要解释
android:layout_marginStart
android:layout_marginEnd
android:layout_marginLeft
android:layout_marginTop
android:layout_marginRight
android:layout_marginBottom

layout_constraintHorizontal_bias  调整水平方向或者垂直方向上的力,比如去0.9,那么表示上面的拉力和下面的拉力的比例为1:9,
                                    那么widget肯定向下方便宜。
layout_constraintVertical_bias 

layout_constraintHorizontal_chainStyle
layout_constraintVertical_chainStyle


layout_constraintVertical_weight 当存在chain时,可以通过调整weight来调整比例。

Guideline
note:

1. 当某个widget的width或者height属性为0dp时,表示 match_constraint.即会被拉伸到参考widget。
2. layout_constraintHorizontal_chainStyle 默认值为spread.


猜你喜欢

转载自blog.csdn.net/qq_33913324/article/details/79943824