safari safari - 2 months ago 18
Android Question

RecyclerView with Scrollable CardView

What I'd like to do




I've got a
RecyclerView
with different
CardView
's inside. For that I wrote a
RecycleView.Adapter
with a
RecyclerView.ViewHolder
. Which works perfectly fine.

Now I'd like to have cards which host a
ScrollView
. My
Layout
for that looks as follows:

<?xml version="1.0" encoding="utf-8"?>




<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">

<TextView
android:id="@+id/tv_assignment_comments_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="false"
android:gravity="left"
android:text="Kommentare"
android:textSize="@dimen/abc_text_size_large_material" />


<ScrollView
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="@id/tv_assignment_comments_title"
android:fillViewport="true">

<LinearLayout
android:id="@+id/ll_comments_card_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
</RelativeLayout>




So far so good. The Card gets displayed but I can't scroll the content inside the ScrollView only the RecyclerView itself.

How can I make my ScrollView scrollable inside the RecyclerView? Can someone show me the magic?

Answer

I could solve the problem by adding following to my RecyclerView.ViewHolder:

mCommentsHolder.mCommentsScrollContainer.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    return false;
                }
            });

Now it works perfectly smooth. I've got that from here.