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.
Related
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.
I want to know when to use ScrollView or ListView or RecyclerView and also Can we use WebView for building an app?
SCROLLVIEW
ScrollView is used to put different or same child views or layouts and the all can be scrolled.
Listview
ListView is used to put same child view or layout as multiple items. All these items are also scrollable.
Simply ScrollView is for both homogeneous and heterogeneous collection. ListView is for only homogeneous collection.
What is RecyclerView?
The RecyclerView widget is a more advanced and flexible version of ListView.
Why RecyclerView?
RecyclerView is a container for displaying large data sets that can be scrolled very efficiently by maintaining a limited number of views.
When you should use RecyclerView?
You can use the RecyclerView widget when you have data collections whose elements
changes at runtime based on user action or network events.
WEBVIEW
WebView in Android turns the application into a web application. It comes from
android.webkit.WebView. Here, the WebView class is an extension of Android's View
class which is used to show the web pages. WebView doesn't include all the features
of Web-browser-like navigation controls or an address bar etc.
I have a ScrollView that contains several other views and I would like for one of these views to be a grid of other views having the same layout (e.g. ImageView).
Since having one scrollable view inside another is not recommended, I would like this grid view not to be scrollable, otherwise I would have used GridView or RecyclerView.
Surely I can place the grid views inside one of the standard layouts (e.g. TableLayout) but this may cause memory issues when many grid items exist.
Is there any standard approach or a library that allows to recycle views for a non scrollbale view inside ScrollView?
If you try to force GridView or RecyclerView to be non-scrollable (so basically you would have to force the dimensions of the view to display all the elements) you will end up in the same situation as if you used TableLayout (so you would need to watch out for memory issues).
If you disable the scrolling of scrollable (recycling) elements like GridView/RecyclerView you disable the most important part that makes those things work efficiently (that makes those things reuse their views).
The way you should solve your issue is to implement your other Views of your ScrollView as a part of the RecyclerView. Your RecyclerView should be equipped with the adapter that can inflate multiple types of Views (you can read about it for example here).
Since you are using RecyclerView you could use NestedScrollView instead of ScrollView They should play more nicely since RecyclerView extends from NestedScrollingChild and NestedScrollView extends from NestedScrollingParent.
Other views you can use are VerticalGridView or HorizontalGridView but as you said you are worried about performance issues and you can provide a GridLayoutManager to the RecyclerView I would stick with that.
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
I'm making a GUI with two different parts. The first part (at the top) is composed of some banners, several fixed buttons. So I think using LinearLayout is the most straightforward way to implement. The second part is composed of several similar items grouped together which can be implemented by using ExpandableListView, I think.
However the problem is that the content exceeds the screen size. So I intend to put two of them into a ScrollView. I checked several sources, it seems that putting "ExpandableListView" inside a ScroolView is NOT possible, or not efficent, so I'm afraid...
Would you help to confirm if this is possible? efficient ?
If no, would you give me some recommendations for this layout design?
I'm indeed looking forward to your supports.
Sincerely.
If you have a fixed header at the top of a list, use ListView's header view feature.
Putting ListViews in ScrollViews fundamentally makes no sense and here is why:
ListView has one purpose: to efficiently display unbounded data sets. Since these can be extremely large (tens of thousands of items and more) you do not want to create a View for each item up front. Instead, ListView asks its Adapter for Views only for the items that currently fit in the ListView's measured space on screen. When an item's View is scrolled out of sight, ListView disconnects that View and hands it back to the adapter to fill out with new data and reuse to show other items. (This is the convertView parameter to an Adapter's getView method.)
ScrollView also has one purpose: to take a single child view and give it "infinite" vertical space to fit within. The user can then scroll up and down to see the full content.
Now given this, how many item Views would a ListView create for a 100,000 item Adapter if it had infinite height available to fill? :)
By putting a ListView inside a ScrollView you defeat ListView's key purpose. The parent ScrollView will give the ListView effectively infinite height to work with, but ListView wants to have a bounded height so that it can provide a limited window into a large data set.
Well Expandable List View itself has scrollable property by placing it in scroll view is really undesirable.As the both scroll would contradict and smooth scrolling can't be obtained in that case..
If we have any data to be shown prior or later to list...
Best way is to use header and footer view to list...
I recommend you use header and footer in your case.