BeginnerProgrammer
BeginnerProgrammer

Reputation: 714

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?

Upvotes: 0

Views: 454

Answers (2)

Lekr0
Lekr0

Reputation: 733

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>

Upvotes: 2

Mohamed Nabil
Mohamed Nabil

Reputation: 1

you can use RecyclerView with GridLayoutManager Class more about here GridLayoutManager

GridLayoutManager recyclerViewLayoutManager = new GridLayoutManager(context,2);//context is your activity and 2 is number of columns 

Upvotes: 0

Related Questions