关于ConstraintLayout的小Tips

2019-07-20  本文已影响0人  冷师傅_

最近在研究MotionLayout的动画,发现了一个有意思的动画,在研究的过程中发现了一个关于ConstraintLayout定位的小技巧。

准备知识

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                   xmlns:app="http://schemas.android.com/apk/res-auto"
                                                   android:orientation="vertical"
                                                   android:layout_width="match_parent"
                                                   android:layout_height="match_parent">

    <View android:layout_width="0dp" android:layout_height="100dp"
          android:layout_marginTop="100dp"
          android:background="@color/colorPrimary"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintLeft_toLeftOf="parent"
          android:id="@+id/view"
    />

    <View android:layout_width="100dp" android:layout_height="100dp"
          android:id="@+id/View2"
          app:layout_constraintLeft_toLeftOf="parent"
          app:layout_constraintRight_toRightOf="parent"
          android:background="@android:color/holo_red_dark"
          app:layout_constraintTop_toBottomOf="@+id/view"
          app:layout_constraintBottom_toBottomOf="@+id/view"
          android:textSize="20sp"
          android:text="hahahahahah"
    />


</androidx.constraintlayout.widget.ConstraintLayout>

小技巧

总结

这个小Tips在我们实现MotionLayout动画的时候应该会用的上。

上一篇下一篇

猜你喜欢

热点阅读