美文网首页
ConstraintLayout学习资料

ConstraintLayout学习资料

作者: MissPSTime | 来源:发表于2020-05-08 09:50 被阅读0次

    https://www.jianshu.com/p/17ec9bd6ca8a

    <?xml version="1.0" encoding="utf-8"?>

        xmlns:app="http://schemas.android.com/apk/res-auto"

        android:layout_width="match_parent"

        android:layout_height="match_parent">

    <!--左和父左对齐-->

            android:id="@+id/ttt"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="122223"

            app:layout_constraintLeft_toLeftOf="parent"

            app:layout_constraintTop_toTopOf="parent" />

    <!--layout_goneMarginLeft当左边的控件消失时,margin值会生效-->

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="sssss"

            app:layout_constraintLeft_toRightOf="@id/ttt"

            app:layout_constraintTop_toTopOf="parent"

            app:layout_goneMarginLeft="10dp" />

    <!--四个方向和父类对其,居中,上下和父类对其时上下居中,左右同理-->

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="居中"

            app:layout_constraintBottom_toBottomOf="parent"

            app:layout_constraintLeft_toLeftOf="parent"

            app:layout_constraintRight_toRightOf="parent"

            app:layout_constraintTop_toTopOf="parent" />

    <!--在某个方向剧中后,使用偏移属性,在当前方向偏移0到1,比如0.5,那么空间的中线对应0.5-->

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="偏移"

            app:layout_constraintBottom_toBottomOf="parent"

            app:layout_constraintHorizontal_bias="0.3"

            app:layout_constraintLeft_toLeftOf="parent"

            app:layout_constraintRight_toRightOf="parent"

            app:layout_constraintTop_toTopOf="parent"

            app:layout_constraintVertical_bias="0.3" />

    <!--尺寸约束-->

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_marginLeft="60dp"

            android:layout_marginTop="60dp"

            android:text="尺寸"

            app:layout_constraintLeft_toLeftOf="parent"

            app:layout_constraintRight_toRightOf="parent"

            app:layout_constraintTop_toTopOf="parent" />

    <!--正方形宽高比(某一个尺寸为0)-->

        <!--除此之外,在设置宽高比的值的时候,还可以在前面加W或H,分别指定宽度或高度限制。 例如:app:layout_constraintDimensionRatio="H,2:3"指的是 高:宽=2:3

    app:layout_constraintDimensionRatio="W,2:3"指的是 宽:高=2:3-->

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_marginLeft="100dp"

            android:layout_marginTop="100dp"

            android:text="等宽高"

            app:layout_constraintDimensionRatio="1:1"

            app:layout_constraintLeft_toLeftOf="parent"

            app:layout_constraintRight_toRightOf="parent"

            app:layout_constraintTop_toTopOf="parent" />

    <!--链式-->

            android:id="@+id/TextView1"

            android:layout_width="0dp"

            app:layout_constraintHorizontal_weight="1"

            android:layout_height="wrap_content"

            app:layout_constraintLeft_toLeftOf="parent"

            app:layout_constraintTop_toTopOf="parent"

            android:layout_marginTop="450dp"

            android:text="text1"

            app:layout_constraintHorizontal_chainStyle="spread_inside"

            app:layout_constraintRight_toLeftOf="@+id/TextView2" />

            android:id="@+id/TextView2"

            android:layout_width="0dp"

            app:layout_constraintHorizontal_weight="1"

            android:layout_height="wrap_content"

            app:layout_constraintLeft_toRightOf="@+id/TextView1"

            app:layout_constraintRight_toLeftOf="@+id/TextView3"

            app:layout_constraintTop_toTopOf="parent"

            android:layout_marginTop="450dp"

            android:text="text2"

            />

            android:id="@+id/TextView3"

            android:layout_width="0dp"

            app:layout_constraintHorizontal_weight="1"

            android:layout_height="wrap_content"

            app:layout_constraintLeft_toRightOf="@+id/TextView2"

            app:layout_constraintRight_toRightOf="parent"

            app:layout_constraintTop_toTopOf="parent"

            android:layout_marginTop="450dp"

            android:text="text3"/>

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            app:layout_constraintLeft_toLeftOf="parent"

            app:layout_constraintBottom_toBottomOf="parent"

            app:layout_constraintRight_toRightOf="@id/gl"

            android:text="guideline1"/>

            android:id="@+id/gl"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:orientation="vertical"

            app:layout_constraintGuide_percent="0.5"

            />

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            app:layout_constraintRight_toRightOf="parent"

            app:layout_constraintBottom_toBottomOf="parent"

            app:layout_constraintLeft_toLeftOf="@id/gl"

            android:text="guideline2"/>

    相关文章

      网友评论

          本文标题:ConstraintLayout学习资料

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