Simple Android grid example using RecyclerView with GridLayoutManager like the old GridView

0 votes

I know that RecyclerView has replaced the functionality of the old ListView and GridView. I am looking for a very basic example that shows a minimal grid setup using RecyclerView. I am not looking for long tutorial style explanations, just a minimal example. I imagine the simplest grid that mimics the old GridView would consist of the following features:

  • multiple cells per row
  • single view in each cell
  • responds to click events
Nov 10, 2022 in Android by Edureka
• 13,620 points
835 views

1 answer to this question.

0 votes

This is a simple way from XML only

spanCount for the number of columns

layoutManager for making it grid or linear(Vertical or Horizontal)

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/personListRecyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
        app:spanCount="2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

answered Nov 10, 2022 by Edureka
• 12,690 points

Related Questions In Android

0 votes
0 answers

Android: why the ICICI iMobile Pay App shows the "rooted/jailbroken" device with my app?

The ICICI iMobile Pay app displays the ...READ MORE

Nov 9, 2022 in Android by Edureka
• 12,690 points
1,083 views
0 votes
0 answers
0 votes
0 answers

Android Studio: Where is the Compiler Error Output Window?

When I "Run" my project in Android ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,620 points
466 views
0 votes
0 answers

"unable to locate adb" using Android Studio

I've been attempting to test my software ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,620 points
620 views
0 votes
0 answers

Android Grid View Scroll Horizontally

I'm working on a job that pulls ...READ MORE

Sep 22, 2022 in Android by Edureka
• 13,620 points
1,008 views
0 votes
1 answer

How to display Toast in Android?

Use the show() function of the Toast ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 12,690 points
1,437 views
0 votes
1 answer

Running docker on Android

According to the documentation, the Android kernel is ...READ MORE

answered Aug 1, 2018 in Docker by Kalgi
• 52,350 points
3,771 views
0 votes
1 answer

Task Canceled Exception while invoking AWS Lambda

I'm guessing either the TaskCanceledException instance is ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,020 points
2,469 views
0 votes
1 answer

Simple Android RecyclerView example

Begin with a blank activity. The actions ...READ MORE

answered Nov 10, 2022 in Android by Edureka
• 12,690 points
625 views
0 votes
1 answer

Open Contact information in Contact List using Phone Number of Contact Android Studio

You must first obtain the contact's CONTACT ...READ MORE

answered Nov 7, 2022 in Android by Edureka
• 12,690 points
1,059 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP