GridView VS GridLayout in Android Apps - android

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.

Related

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

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.

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.

Rendering GridView inside ListView being slow

I have a ListView with various types of elements. Those elements are retrieved from an API, so they are dynamic. One of the possible elements is a photo gallery where photos must be displayed in pairs. I'm rendering this element using a two columns GridView. In other words: one of the possible ListView elements is a GridView. I know isn't a good practise to embed one ScrollView inside another one, but it's the best approach I've found.
There’s a problem with the ListView rendering, when it reaches the GridView, it freezes because it inflates all the elements inside the GridView regardless which are really going to be shown in the UI. I mean, if the GridView contains 200 elements, it inflates all of them. I don’t know how to make the GridView respect the common pattern of Android GroupViews, just inflate the displayed elements on screen in each particular moment.

Android ScrollView Vs ListView

I´m facing the implementation of a View where I have to load perhaps almost 100 items in a list. I have a doubt in which maybe the best way to implement it.
I already know that ListView recycles the views and ScrollView keeps all in memory. The point is that I was thinking in apply paging to the Scrollview to avoid huge loading times when the app inflates all items.
Applications as Google+, Facebook, twitter or Linkedin, Do you think they use ListView?
Thanks
ListView is definitely the way to go. It's easier to use than ScrollView, and a paging system doesn't fit in with the style of android.
ListView is meant to create a list of varrying lengths based of an array of information. ScrollView is for having a (usually) set amount of children in the View (defined in the layout xml).
ListViews do not inflate all items, they inflate however many can fit on a page at a time. Your fastest option, with or without paging is a ListView. However, if each child is completeley different, then ScrollView is the way to go.

Android TableLayout vs GridView vs Other?

I am developing an app and am looking for some general guidance:
The app is a memory trainer, and will have a couple of different modes:
Numbers: Up to 400 digits will be displayed on the screen in a gridlike pattern
Faces: Images of faces will appear, approximately 9 to a page, also in a grid pattern
The question is: can I accomplish this with a single xml layout file, and should I use the same layout type for each (and if so, what should it be!) ? It's a large app, so consistency would be heavenly.
I would prefer a layout with flexibility, and I am leaning toward GridView right now.
Any thoughts?
A Grid view is basically like a list view where items are arranged in a static grid.
It retrieves views from the Adapters as scrolled by user.
A table layout is a layout manager and does not do scrolling if required.this means u have to put it inside a scroll view. This implies that all of the data you are displaying must be populated into the TableLayout up-front, so the ScrollView knows the total space it is to scroll in. It also does not directly give you per-"item" selection or interaction, because a TableLayout doesn't have items, it is just a layout manager.
Also Adapter -based view should be used where significant amount of data is there to be scrolled. So it seems that grid view would be more suitable in the situation u r working.

Categories

Resources