Skip to content

Latest commit

 

History

History
51 lines (45 loc) · 3.16 KB

constraint-layout.md

File metadata and controls

51 lines (45 loc) · 3.16 KB

ConstraintLayout

<MotionScene>

  • must contain at least one <Transition>.
  • When using MotionLayout, all the constraints of animated views must be specified in <MotionScene>. The constraints of non-animated views can be specified in <MotionLayout>.

<Transition>

  • is one animation.
  • contains the following attributes
    • constraintSetStart
    • constraintSetEnd
    • duration
    • Optionally, <KeyFrameSet>

<KeyFrameSet>

  • contains at least one <KeyPosition>.

At framePosition modify the path of motionTarget by moving it by percentX or percentY according to the coordinates determined by keyPositionType.

<KeyPosition>

  • never affects start and end constraints.
  • never affects other views that are constained to the view associated with <KeyPosition>.

<ConstraintSet>

  • is the start and the end constraints of a motion.
  • contains <Constraint>(s).
  • contains only constraints or layout information such as width, height, alpha, or visibility, but not views.
  • whose constraints override constraints in a layout file.

RelativeLayout vs. ConstraintLayout

RelativeLayout ConstraintLayout
android:layout_centerInParent="true" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf=""parent"
android:layout_centerVertical="true" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_centerHorizontal="true"" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_alignParentTop="true" app:layout_constraintTop_toTopOf="parent"
android:layout_alignParentBottom="true" app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentStart="true" app:layout_constraintStart_toStartOf="parent"
android:layout_alignParentEnd="true" app:layout_constraintEnd_toEndOf="parent"
android:layout_alignTop="@id/view" app:layout_constraintTop_toTopOf="@id/view"
android:layout_alignBottom="@id/view" app:layout_constraintBottom_toBottomOf="@id/view"
android:layout_alignStart="@id/view" app:layout_constraintStart_toStartOf="@id/view"
android:layout_alignEnd="@id/view" app:layout_constraintEnd_toEndOf="@id/view"
android:layout_alignBaseline="@id/view" app:layout_constraintBaseline_toBaselineOf="@id/view"
android:layout_above="@id/view" app:layout_constraintBottom_toTopOf="@id/view"
android:layout_below="@id/view" app:layout_constraintTop_toBottomOf="@id/view"
android:layout_toStartOf="@id/view" app:layout_constraintEnd_toStartOf="@id/view"
android:layout_toEndOf="@id/view" app:layout_constraintStart_toEndOf="@id/view"