Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

Horizontal RecyclerView inside horizontal ScrollView only scrolling RecyclerView in Android Studio

What I want to achieve:

I have a horizontal ScrollView that has two elements: a CardView and a horizontal RecyclerView. So, when the user scrolls horizontally, I want the two elements to scroll.

What results do I expect:

I want to have something like this: Goal, where the orange line is the CardView and the yellow one the RecyclerView. When the user scrolls, the two elements scrolls, as shown here: Scrolled goal.

Actual results

Right now in my App, when the user scrolls only the RecyclerView scrolls. The CardView stays in his position.

What have I tried

I have tried a lot of different layouts: having a NestedScrollView with an LinearLayout inside that contains both elements, a RelativeLayout, a ConstraintLayout... Right now, I have a ConstraintLayout:

 <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:orientation="horizontal">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent">

               <-- Card Content !-->
            </androidx.cardview.widget.CardView>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:overScrollMode="never"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/cardView3">
            </androidx.recyclerview.widget.RecyclerView>

        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>
question from:https://stackoverflow.com/questions/65921566/horizontal-recyclerview-inside-horizontal-scrollview-only-scrolling-recyclerview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The solution: using a HorizontalScrollView and setting the property setNestedScrollingEnabled to false in the RecyclerView.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...