Two Recycler Views inside a MotionLayout creating problems

Viewed 360

I am new in using Motion Layout and I have used two Recycler views rv_horizontal and rv_vertical ,rv_horizontal is using LinearLayout Manger with horizontal orientation and rv_vertical is using GridLayout Manger. I have used both of them within Motion Layout. What I want is,when I scroll up the rv_vertical then rv_horizontal, along with the Text ViewtxtCategory, should disappear. What I tried is following:

home.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".Home"
    android:background="@color/bgcolor"
    app:layoutDescription="@xml/fragment_home_scene">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:id="@+id/txtCategory"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="@string/category"
        android:textSize="8pt"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/txtCategory"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@+id/txtFamousPlaces"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:text="@string/famous_places"
        android:textSize="8pt"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/rv_horizontal" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_vertical"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/txtFamousPlaces"
        app:layout_constraintVertical_bias="0.0" />


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

SceneFile of Home Fragment i.e., home_scene.xml :

<?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">
        <Constraint android:id="@+id/txtCategory"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />
        <Constraint
            android:layout_height="wrap_content"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_width="match_parent"
            app:layout_constraintTop_toBottomOf="@id/txtCategory"
            android:id="@+id/rv_horizontal"
            app:layout_constraintBottom_toTopOf="@+id/txtFamousPlaces" />
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint android:id="@id/txtCategory"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />
        <Constraint
            android:layout_height="0dp"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_width="match_parent"
            app:layout_constraintTop_toBottomOf="@id/txtCategory"
            android:id="@+id/rv_horizontal"
            app:layout_constraintBottom_toTopOf="parent" />
    </ConstraintSet>

    <Transition
        app:constraintSetEnd="@id/end"
        app:constraintSetStart="@+id/start">
        <OnSwipe
            motion:onTouchUp="stop"
            motion:dragDirection="dragUp"
            motion:touchAnchorId="@+id/rv_vertical"
            app:moveWhenScrollAtTop="true"/>
    </Transition>
</MotionScene>

I am facing the following problems, if anyone knows please help me:

  1. I am scrolling up the rv_vertical but nothing is happening , although I have set the attribute motion:touchAnchorId="@+id/rv_vertical" within OnSwipe attribute in home_scene.xml file. As you can see.

Image1

  1. When I scroll up the FamousPlaces then scroll down it then recycler view rv_horizontal does not load completey. As following

Image2

I tell you again what I want is,when I scroll up the rv_vertical, rv_horizontal, along with the Text ViewtxtCategory, should disappear.And when I scroll down rv_vertical, rv_horizontal should loaded completely. If anybody knows please help me.

0 Answers
Related