ConstraintLayout

ConstraintLayout 继承自ViewGroup。
1、约束类型:
相对定位
 
允许将指定的控件添加约束条件
  • 水平轴:left 、right、start、end
  • 垂直轴:   top、bottom、text baseline
可用约束:
  • layout_constraintLeft_toLeftOf
  • layout_constraintLeft_toRightOf
  • layout_constraintRight_toLeftOf
  • layout_constraintRight_toRightOf
  • layout_constraintTop_toTopOf
  • layout_constraintTop_toBottomOf
  • layout_constraintBottom_toTopOf
  • layout_constraintBottom_toBottomOf
  • layout_constraintBaseline_toBaselineOf
  • layout_constraintStart_toStartOf
  • layout_constraintEnd_toStartOf
  • layout_constraintEnd_toEndOf 
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A"
    />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="136dp"
            android:text="B"
            app:layout_constraintLeft_toRightOf="@+id/button2"
    />
    
    </android.support.constraint.ConstraintLayout>

    按钮B 的 左侧约束到按钮A的右侧

    2、边距
    当位置约束目标为View.GONE ,以下属性指示生效
    • layout_goneMarginStart
    • layout_goneMarginEnd
    • layout_goneMarginLeft
    • layout_goneMarginTop
    • layout_goneMarginRight
    • layout_goneMarginBottom
     
    3、定位

    居中

    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRight="parent"

    居中偏移定位

    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintLeft_toRightOf="parent"
    //水平居中往左偏移  0-1
    app:layout_constraintHorizontal_bias="0.2"
    //垂直偏移
    app:layoutapp:layout_constraintVertical_bias="0.2"
    圆弧定位
    使用角度和距离,约束控件B相对于控件A的中心
    app:layout_constraintCircle="@+id/button2"
    app:layout_constraintCircleRadius="100dp"
    //角度0-360
    app:layout_constraintCircleAngle="120"

     

posted @ 2019-07-27 19:48  CoCoBill  阅读(223)  评论(0编辑  收藏  举报