androidandroid-drawableandroid-motionlayout

Motion Layout set drawable


I have a custom drawable with them shapes, strokes, and color and I'd like the transition to change from one to another drawable. My question here is, what is the right attributeName and custom value to make it work?

I've already tried with this one:

    <CustomAttribute
        app:attributeName="background"
        app:customColorDrawableValue="@drawable/border_right_radius_5"/>

Tried other options but it doesn't seem to work. Any idea?


Solution

  • You can create two ImageView with same constraints and fade them in and out

    <androidx.constraintlayout.widget.ConstraintLayout>
    
        <ImageView
            android:id="@+id/iv1"
            ...
            android:visibility="visible"
            app:srcCompt="@drawable/shape1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent" />
    
        <ImageView
            android:id="@+id/iv2"
            ...
            android:visibility="invisible"
            app:srcCompt="@drawable/shape2"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent" />
    
    <androidx.constraintlayout.widget.ConstraintLayout>
    

    And

    <MotionScene>
        ...
        <ConstraintSet android:id="@+id/end">
        
            <Constraint
                android:id="@+id/iv1"
                android:visibility="invisible"
                ... />
        
            <Constraint
                android:id="@+id/iv2"
                android:visibility="visible"
                ... />
        
        </ConstraintSet>
    
    </MotionScene>