What is difference between GridView, GridLayout and Recycler view with GridLayout? - android

I am developing an app in which i need a layout like provided images.
Which layout should i use? and why ?
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.

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.
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!!
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:
https://developer.android.com/reference/android/widget/GridLayout
https://developer.android.com/reference/android/widget/GridView
https://developer.android.com/guide/topics/ui/layout/recyclerview
https://medium.com/google-developer-experts/android-grid-layout-1faf0df8d6f2

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.

Related

Xamarin Forms - how to create a Horizontal ListView in xaml?

How to create Horizontal listview that has maximum of 3 row and more column it depends on the data just like in this picture
Link:https://i.stack.imgur.com/cUJjB.jpg
This is my concept don't mind the design i just want to know how to create that kind of list view
You can try FlexLayout.
FlexLayout is similar to the Xamarin.Forms StackLayout in that it can
arrange its children horizontally and vertically in a stack. However,
the FlexLayout is also capable of wrapping its children if there are
too many to fit in a single row or column, and also has many options
for orientation, alignment, and adapting to various screen sizes.
More information can be found in the official documentation.
Set the ItemsPanel of the ListView to a horizontal StackPanel.
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
From this question.
Edit: This solution may actually not work for you. If it doesn't work, take a look at this library. It might help you.

Android-Appropriate View For Horizontal & Vertical Scrolling Grid

I am new to Android and looking for advice on which particular view or views to use for an app. I am attempting to create an epg. I have done this on another platform and was wanting to migrate to android. After alot of reading and looking at examples I am little confused. To make a horizontal and vertical scrolling grid, would the gridview alone be enough to display the program titles. I say gridview alone, I mean the gridview in the main activity with a textview in resource xml. If not can somebody point me in the right direction, not asking for code just advice on the best way to go about the project. I am not worried about a channel list or time slot list only displaying the programming title in columns and rows that can scroll both directions. I anticipate the channel list being in a recyclerview separate form the grid. Thanks for advice.
I will suggest you to use cardview. Because gridview will give you 2 dimensional view which is not more customizable. Better you can go with cardview.
For cardview, you need to add dependency. You can use cardview inside recycler view.
GridView - GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a List Adapter. GridViews are particularly useful for displaying images in a structured fashion, for example if you’re designing a gallery app. To populate a GridView with data (whether that’s images, text, or a combination of the two) you’ll need to bind your data to the GridView using a ListAdapter
CardView - To create complex lists and cards with material design styles in your apps, you can use the RecyclerView and CardView widgets. CardView gives you an easy way of displaying data in Google Now-style cards. The Android SDK doesn’t include the CardView class, so you’ll need to add the CardView support library before you can use cards in your project.
To get bettter idea, you can visit this link.

Google play store like interface using recycler view

My assignment is to create an interface much same like Google Play Store.There will a Category name followed by 3 or 4 cards (horizontal) followed by More button. Then again next category.
I already had implemented this using nesting the horizontal listview inside Vertical listview.
I know, I can achieve this by using the Recycler view with LinearLayoutManager with horizontal orientation. Using this I'll be having one only row.
My question is how do I add 2nd, 3rd row to this?
Should I use again nested Recycler view?
Are there some better options?
Dont use nested listviews (you cant scroll horizontally in play store).
Consider the following options:
You can use a simple LinearLayoutManager and make different view types. For the with 3 cards horizontally use a GridLayout or LinearLayout with same weights. The problem here is, that you have to consider the indexes of your underlying data list used in the adapter
Write your own LayoutManager for RecyclerView
Use TwoWay View which is based on RecyclerView and offers a Spannable Grid Layout manager, which seems to be what you are looking for.
If you inspect the layout of the Google Play app, they do not use a listview/recyclerview for the horizontal cards. I'm pretty sure that is just a linearlayout (horizontal) within a vertical listview / recyclerview.
If you insist on using a horizontal recyclerview for each row, then having a nested recyclerview would be your best option. You can specify a RecycledViewPool so that all the nested recyclerviews share the same pool instead of creating their own.
You may like to do it as one vertical RecyclerView (Main recycler) and for every section you can inflate a horizontal RecyclerView as well (Section recycler) as this blog answer mention:
Also, consider using:
A cache layer for Bitmaps for persistent access through your other store screens
A lazy load method for your category/section images
A place holder before showing new items

Autosizing GridView

Is there any lib that can help me to achieve what CollagePlus jQuery library does?
I have a list of pictures (link and dimensions). Dimensions could be different and i need to arrange all images inside one view like in attached screen.
Update. I have a listView (RecyclerView), each item could have such gridView - so layout_height has to be wrap_content.
I've tried StaggeredGrid - that's not exactly what i want.
Also tried AsymmetricGridView - very buggy.
the support library there's the new RecyclerView that can achieve exactly that, you just have to use the GridLayoutManager and supply a SpanSizeLookup
here are the links for the docs
https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html
https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html
https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.SpanSizeLookup.html
This should help you achieve what you want. It's etsy's staggered grid view. Well supported.
https://github.com/etsy/AndroidStaggeredGrid

GridView VS GridLayout in Android Apps

I have to use a Grid to implement Photo Browser in Android.
So, I would like to know the difference between GridView and GridLayout.
So that I shall choose the right one.
Currently I'm using GridView to display the images dynamically.
A GridView is a ViewGroup that displays items in two-dimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view.
This is what you'd want to use (keep using). Because a GridView gets its data from a ListAdapter, the only data loaded in memory will be the one displayed on screen.
GridViews, much like ListViews reuse and recycle their views for better performance.
Whereas a GridLayout is a layout that places its children in a rectangular grid.
It was introduced in API level 14, and was recently backported in the Support Library.
Its main purpose is to solve alignment and performance problems in other layouts.
Check out this tutorial if you want to learn more about GridLayout.

Categories

Resources