2

I am developing an app in which i need a layout like provided images.

  1. Which layout should i use? and why ?
  2. What is difference between GridView and GridLayout ? why they are in legacy section ? What are alternatives and best practices ?

Following are the layout i need to develop. i can achieve this layout many ways but i need to know best practices.

enter image description here

enter image description here

Faisal Imran
  • 201
  • 1
  • 11

2 Answers2

2

I believe I came across the same problem you had. From the google documentation websites above and this answer GridView VS GridLayout in Android Apps, I got a clue.

  1. use GridLayout when you only want to position your children view widgets in an aligned way. In this case, the children should be not be scrolled. Grid Layout does not support recycling, which will scrap old children items that is not on the screen while recycling their view holders. So your children views should not be too many to handle otherwise an OMM will occur!!
  2. if it is not fo the case 1, I believe we should use recycler view. When your children items may be in the scale of 10 + or cannot be fitted under the screen, you'd better use recycler view. GridView is added since API 1. If you try to click the GridView guide link in the GridView reference guide, you will be redirected to Recycler View guide website. In this website, I quote
  • GridLayoutManager arranges the items in a two-dimensional grid, like the squares on a checkerboard. Using a RecyclerView with GridLayoutManager provides functionality like the older GridView layout.

  • StaggeredGridLayoutManager arranges the items in a two-dimensional grid, with each column slightly offset from the one before, like the stars in an American flag.

Google also has a sample code for recycler view https://github.com/android/views-widgets-samples

This is the websites that I looked into:

Community
  • 1
  • 1
JoyAndroid
  • 21
  • 3
0

https://stackoverflow.com/a/11307615/10075771

this will help you understand more about gridview and gridlayout. And for my opinion, as what i see in the layout you want to achieve, its best way to use gridview.

No Name
  • 392
  • 1
  • 4
  • 18
  • 1
    Gridview and gridlayout are in legacy section that means they aren't recommended. is that right ? – Faisal Imran Dec 01 '18 at 14:54
  • if its recommended or not. its your choice what will help you achieve that kind of layout and will support into your layout in different sizes of device. – No Name Dec 03 '18 at 03:19