5

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
  • 269
  • 2
  • 15

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 align the position of your child view widgets. In this case, the children should not be scrolled. Grid Layout does not support recycling, which will scrap old child views that are not on the screen and recycle their view holders. You should not have too many child views, otherwise an OMM will occur!!
  2. if it is not case 1, I believe we should use recycler view. When your children items may be in the scale of 10 + or cannot fit on the screen, you'd better use recycler view. GridView is available 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 sample code for recycler view at https://github.com/android/views-widgets-samples

These are the websites that I looked into:

Abandoned Cart
  • 4,512
  • 1
  • 34
  • 41
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
  • 472
  • 1
  • 6
  • 19
  • 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
  • It's very bad advice to implicitly recommend obselete and deprecated practices, especially if something is newly designed from scratch, anyway. – Akito Dec 01 '21 at 22:30