ConstraintLayout的一点理解

1、相对定位
app:layout_constraintLeft_toRightOf="@+id/tv_threee"

上面的constraintLeft 我当前控件自己 我的左边 约束到 控件id是 tv_three 的右边 toRightOf="@+id/tv_threee" 相对于RelativeLayout 的to_rightof

2、角度定位和 基本约束 (注意:这两个约束只定义了垂直约束 水平约束一定要加上
 <TextView
        android:id="@+id/tv_one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:text="@string/view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"></TextView>


    <TextView
        android:id="@+id/tv_two"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/view2"
        app:layout_constraintCircle="@+id/tv_one"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintCircleAngle="200"
        app:layout_constraintCircleRadius="120dp"
        app:layout_constraintTop_toTopOf="parent"></TextView>

基线

  <TextView
        android:id="@+id/tv_threee"
        android:text="我是一个兵"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>

    <TextView
        app:layout_constraintLeft_toRightOf="@+id/tv_threee"
        android:text="一个大兵"
        android:textSize="40sp"
        app:layout_constraintBaseline_toBaselineOf="@+id/tv_threee"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>
3、gongMargin的时候一定要注意 被参考控件的高度
 <TextView
        android:visibility="gone"
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:text="这是在底部"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_goneMarginBottom="25dp"></TextView>


    <TextView
        android:layout_marginBottom="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/textView2"
        android:text="我也是一个兵"
        app:layout_goneMarginLeft="15dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>
4、水平偏移(控件首先要约束成水平居中)和垂直偏移(控件首先约束成垂直居中)
 <TextView
        android:id="@+id/textView3"
        android:layout_marginBottom="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/textView2"
        android:text="我也是一个兵"
        app:layout_goneMarginLeft="15dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>


    <TextView
        android:text="水平偏移"
        app:layout_constraintHorizontal_bias="0.3"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintVertical_bias="0.7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值