Search code examples
androidandroid-recyclerviewandroid-gridview

How to enable scrolling of grideview inside a recyclerview?


I have a recycler view which the item of this recycler view is like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/question_bkg"
    android:orientation="vertical"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/questionTitle"
        android:padding="10dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/dynamicLayout"
        android:layout_below="@id/questionTitle"
        android:layout_alignParentLeft="true"></LinearLayout>
    <GridView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/dynamicLayout"
        android:numColumns="2"
        android:id="@+id/questionChoicesRecycler"></GridView>
</RelativeLayout>

When I have set the recyclerView.setNestedScrollingEnabled(true); but still i can not scroll inside gridview. How can I fix this? Or is there a way to use recycler instead of gridview but with 2 item in a row?


Solution

  • Put your GridView inside a ScrollView.

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
        <GridView
            android:layout_width="match_parent"         
            android:layout_height="match_parent"        
            android:layout_below="@id/dynamicLayout"
            android:numColumns="2"        
            android:id="@+id/questionChoicesRecycler">
        </GridView>
    
    </ScrollView>