0

I'm moving a view from top to bottom of my activity , the problem is ,it works fine and move my view from bottom to up but when the transition completed , it hides the view

this is my layout :

   <androidx.constraintlayout.motion.widget.MotionLayout
            android:id="@+id/fist_motionlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutDescription="@xml/fistactivity_motions"
            app:showPaths="true">

            <include
                android:id="@+id/appbar"
                layout="@layout/appbar"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.cardview.widget.CardView
                android:id="@+id/marque"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                app:cardBackgroundColor="#395471"
                app:cardCornerRadius="7dp"
                app:cardElevation="1dp"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                app:layout_constraintTop_toBottomOf="@+id/appbar"
                tools:visibility="visible">

            </androidx.cardview.widget.CardView>

            <FrameLayout
                android:id="@+id/fm_firstact_content"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/marque" >

</FrameLayout>

        </androidx.constraintlayout.motion.widget.MotionLayout>

this is my xml code:

  <?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:motion="http://schemas.android.com/tools">

    <ConstraintSet android:id="@+id/start_set">
        <Constraint
            android:id="@+id/fm_firstact_content"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent"></Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end_set">
        <Constraint
            android:id="@+id/fm_firstact_content"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/marque"></Constraint>
    </ConstraintSet>

    <Transition
        android:id="@+id/trans_firstact_fm_content"
        app:constraintSetEnd="@id/end_set"
        app:constraintSetStart="@id/start_set"
        app:duration="2000"></Transition>
</MotionScene>

and in the activity , I just start it:

 MotionLayout ml=vf.findViewById(R.id.fist_motionlayout);
    ml.transitionToEnd();

when I run the app, it moves the view from bottom to top and suddenly it get invisible , and strange thing is when I run the activity again from another activity , it works fine and it doesn't get invisible but if I close the app and run it again , it gets hide . every time app runs for the first time , view gets hide after the transition completed

this is my gradle :

implementation 'androidx.appcompat:appcompat:1.2.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'androidx.cardview:cardview:1.0.0-alpha01'
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'

how to solve it ?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58

2 Answers2

0

Remove the constraints in your layout for marque cardview and create a constraintset for it in motionscenes xml.when using the motion layout u can't define constraint for view in activity_layout.xml.it will take constraint from motion.xml.so,create constraintset for that card view in motion layout and remove the all constraint in activity layout.

gowtham6672
  • 999
  • 1
  • 10
  • 22
0

If you are going to base your motionScene constraints on a view, it should be defined inside the motionScene as well. I have moved your constraint information for all views within the motionLayout into the motionScene so now it should work as expected. It may need small tweaks but try this:

Your layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout 
    android:id="@+id/fist_motionlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/fistactivity_motions"
    app:showPaths="true"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <include
        android:id="@+id/appbar"
        layout="@layout/appbar"/>

    <androidx.cardview.widget.CardView
        android:id="@+id/marque"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        app:cardBackgroundColor="#395471"
        app:cardCornerRadius="7dp"
        app:cardElevation="1dp"
        android:layout_marginLeft="1dp"
        android:layout_marginRight="1dp"
        tools:visibility="visible"/>

    <FrameLayout
        android:id="@+id/fm_firstact_content"
        android:layout_width="0dp"
        android:layout_height="0dp" />
</android.support.constraint.motion.MotionLayout>

and your motion scene file:

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:motion="http://schemas.android.com/tools">

<ConstraintSet android:id="@+id/start_set">
    <Constraint
        android:id="@+id/fm_firstact_content"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"/>

    <Constraint
        android:id="@+id/marque"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/appbar"/>

    <Constraint
        android:id="@+id/appbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>

<ConstraintSet android:id="@+id/end_set">
    <Constraint
        android:id="@+id/fm_firstact_content"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/marque"/>

    <Constraint
        android:id="@+id/marque"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/appbar"/>

    <Constraint
        android:id="@+id/appbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>

<Transition
    android:id="@+id/trans_firstact_fm_content"
    app:constraintSetEnd="@id/end_set"
    app:constraintSetStart="@id/start_set"
    app:duration="2000"/>
</MotionScene>

Again, it may need some small tweaks but this is the direction you should go to fix your issue

kjanderson2
  • 1,209
  • 12
  • 23