Google play store like interface using recycler view - android

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

Related

Android. RecyclerView track viewed items

I have two RecyclerView inside the NestedScrollView and I need track viewed items of my RecyclerViews. But problem that using nestedScrollView the recycler pattern doesn’t work and all the views will be loaded at once because wrap_content needs the height of complete RecyclerView so it will draw all child Views at once.
Is there any way to track of the viewed items with this approach? Please help me.
never use RecyclerView inside NestedScrollView because your ViewHolders will not be recycled and you will be in danger of OutOfMemoeryExceptions, it may work for lists with small sizes but as the list size increases it becomes worse,
instead of using one ScrollView and 2 RecyclerView as child
you have to completely remove ScrollView and instead of that, use one RecyclerView with multitype ViewHolders, in other words you need to combine those 2 RecyclerView in on RecyclerView .
To achieving this you can combine those adapters manually or you can use ConcatAdapter that depends on what you want, this link may also help you if you want to use ConcatAdapter but that is not necessary.
then you can have different approaches to track the visibility of viewHolders like layoutManager.findFirstVisibleItemPosition() and etc.

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.

Which Recyclerview or ScrollView should I choose?

I created an activity with a ListView. That is a Friend ListView.
I wanna let it choose to add it to another View.
I don't know which View to choose is the best. Recyclerview or ScrollView?
Like this
Basic difference between RecyclerView and ListView are the below.
ListView is simple to implement. Default Adapters available.
But ViewHolder pattern and finding views using ID's used to give slow performance.
Now in RecyclerView , the above problems are attended using RecyclerView.ViewHolder.
For RecyclerView adapter, this ViewHolder is mandatory. While comparing to list view this is kinda complex, but solves performance issues in ListView.
Difference LayoutManagers are available while using RecyclerView.
LinearLayoutManager
StaggeredGridLayoutManager
GridLayoutManager
Major improvement of RecyclerView performance while comparing to ListView would be this according to developer.android.com
The RecyclerView creates only as many view holders as are needed to
display the on-screen portion of the dynamic content, plus a few
extra. As the user scrolls through the list, the RecyclerView takes
the off-screen views and rebinds them to the data which is scrolling
onto the screen
To sumup, RecyclerView is preferable than ListView (when UI is having same widgets repeating according to your data)
Now when to use ScrollView:
Your UI elements may not show completely in small device screens. But in bigger screen sizes it may!
Elements may not be necessarily only list / grid. It can have combinations of any UI widgets.
Eg:- TextViews vertically , with RadioButton and Button at last for user action.
This cannot be included in ListView/ RecyclerView , now you can add ScrollView which will have a LinearLayout/RelativeLayout . Inside which all other elements can be added.
Now you can
I recommend to user always RecyclerView and never a ListView. Use RecyclerView for element list and scrollview for static views.
Seeing your image Scrollview inside RecyclerView or ListView have problems with drag.
Use a vertical RecyclerView in all page and horizontal RecyclerView each row.
I suggest you to use RecyclerView because you will load lots of images and if you use ScrollView eventually you will use so much memory. Also it is recommended to use RecyclerView when you have dynamic data. You can look the definition of the RecyclerView in the Android Documentation as follow
RecyclerView is a view for efficiently displaying large data sets by
providing a limited window of data items.
You can use nested RecyclerView for creating such hierarchal view.
You can also checkout this example for nested RecyclerView usage.
Also you can further read:
Android Recyclerview vs ListView with Viewholder
RecyclerView vs. ListView
Should we use RecyclerView to replace ListView?
I hope this helps.

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.

Android designconsideration for complex screen using recycler view

Following will be the layout in my app
So I am considering of using recycler view. There will be a parent recyclerview, I which I will define different view types for each section e.g, viewpager, horizontal block etc. Depending on view types, different viewholders will be created. Horizontal block will be displayed in horizontal recyclerview. For grid there will be a recycler view in another viewholder. The data for each section will be loaded from a different API. Means the first API will only give metadata, using that metadata, another API will be called whose data will be used to populated in the blocks.
My question is whether is this a good approach to have a parent recycler view, define view types and have other recylerviews inside view olders. As I am nesting recyclerview in other recycler, so should this approach will be fine wrt performance or there is some other way to implement such design.
I am using recycler view as it will be easy to implement pagination.
PS: I am not using linear layout as implementing pagination on linear layout is a bit tricky. I find it more easier in listview/recycler view. Also the sections like list/grid as shown, are dynamic one and there is no fixed number that they will be upto 2 or 5. It can be upto n. So, with linear layout, I have to add all sections in loop which will be overkill if the no. of sections quite large.

Categories

Resources