Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll Textview inside RecyclerView

I have a RecyclerView

<android.support.v7.widget.RecyclerView
            android:id="@+id/activityRecicler"
            android:layout_width="match_parent"
            android:scrollbars="vertical"
            android:layout_height="wrap_content"
            app:stackFromEnd="true"
            />

And I have a row layout:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/description"/>

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/solutions"/>

    </LinearLayout>

And the wrap content work, but my problem is that TextView with id description It could be very long and so, I would have a Scroll for this TextView. How could I do this?

like image 535
LorenzoBerti Avatar asked Aug 03 '16 11:08

LorenzoBerti


1 Answers

Change your layout XML to:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/childScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </ScrollView>

    <TextView
        android:id="@+id/solutions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

And then in your activity:

activityRecicler.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        findViewById(R.id.childScroll).getParent().requestDisallowInterceptTouchEvent(false);
        return false;
    }
});
childScroll.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        // Disallow the touch request for parent scroll on touch of child view
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
});
like image 76
Payal Sorathiya Avatar answered Oct 16 '22 21:10

Payal Sorathiya