Monday, 11 January 2021

How to animate the nested view on constraint layout?

I have a requirement where the view needs to be at the center of bottom and adjust the height based on its content. So created constraint layout inside root constraint layout to acheive this. But now I am facing a problem with animation. I am not able to apply constraintSet.

<androidx.constraintlayout.widget.ConstraintLayout>
     <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/error_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:layout_marginEnd="12dp"
        android:layout_marginBottom="40dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <View
            android:id="@+id/error_view"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:background="@drawable/display_result"
            android:padding="24dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/error_try_again"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:background="@drawable/primary_button"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:text="@string/try_again"
            android:textAlignment="center"
            app:layout_constraintLeft_toLeftOf="@+id/error_view"
            app:layout_constraintRight_toRightOf="@+id/error_view"
            app:layout_constraintTop_toBottomOf="@+id/error_msg" />

        <TextView
            android:id="@+id/error_msg"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/error_msg"
            android:textAlignment="center"
            app:layout_constraintTop_toBottomOf="@+id/empty_space_1"
            app:layout_constraintLeft_toLeftOf="@+id/error_view"
            app:layout_constraintRight_toRightOf="@+id/error_view"
        />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
  • If I need to go with constraintSet how to restructure my layout (without nested groups)?
  • Is there any other way we can achieve like scene or motion layout. I am not sure about this implementation. But I feel like constraintSet is much straight forward to use.


from How to animate the nested view on constraint layout?

No comments:

Post a Comment