0

I want a horizontal moving layout with 3 rows and any no. of columns depending on the number of items fetched from the server. Gridview does set no. of columns but i want to fix no. of rows.

I am specifying a link for the exact layout i want. https://firebasestorage.googleapis.com/v0/b/wassup-b21d5.appspot.com/o/Picture.png?alt=media&token=889a2c74-9d43-4557-8d5e-8ded80212d1e

Ankit Verma
  • 496
  • 5
  • 21

1 Answers1

0

Use RecyclerView with GridLayoutManager. When you create a horizontal GridLayoutManager and set spanCount, it's considered as number of rows and not columns.

recyclerView.layoutManager = GridLayoutManager(requireContext(), 3, HORIZONTAL, false)

If you're not familiar with RecyclerView see this and this.

Reza Mohammadi
  • 106
  • 1
  • 1
  • 6
  • Thanks, There is one more thing as you can see in the image , i have to place the objects alternatively so how will the xml file look like? – Ankit Verma Apr 17 '21 at 06:17
  • Are you talking about white space between items? You can consider two view types for your adapter. A ViewGroup that contains an ImageView and a TextView, and another view that is nothing but just a View with white background. Then in your adapter you can decide which of these two view types should be used for a certain position. For example when position is even then use the first view type and when it's odd use the second one. See this : https://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type. If the answer helped you please mark it as accepted. – Reza Mohammadi Apr 17 '21 at 06:39