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.
Related
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.
I am developing and application that will have to implement the swipe-to-refresh pattern described here. Looking at the android docs here, it is stated that:
You enable this behavior by adding the widget to your layout file as the parent of a ListView or GridView, and implementing the refresh behavior that gets invoked when the user swipes.
Well the issue is that I do not plan on having a ListView or GridView to layout my data, I am using cards (android.support.design.CardView) and I am planning on having a scrolling list of cards that the end user can swipe to refresh.
Can I still use the SwipeToRefreshLayout as described in the tutorial with my cards, or does it force me to use ListViews or GridViews to display my data?
Well as the documentation says that
The SwipeRefreshLayout should be used whenever the user can refresh
the contents of a view via a vertical swipe gesture.
This layout should be made the parent of the view that will be
refreshed as a result of the gesture and can only support one direct
child.
It does not mention that the view must be a ListView or a RecyclerView.
Also as seen in those questions:
SwiperefreshLayout in Android
Android SwipeRefreshLayout how to implement canChildScrollUp if child is not a ListView or ScrollView
Both of them have implemented a SwipeRefreshLayout with LinearLayout as the child View. So yes it will work with the view either being a CardView or a ScrollView.
Hope it helps!!!
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.
Can any one explain the difference between Scroll View and List View? When to use which one? And which one is more efficient?
ScrollView is used to put different or same child views or layouts and the all can be scrolled.
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.
They're completely different.
A ScrollView is simple a scrolling container you can use to scroll whatever you put inside it, which might be a list of items, or it might not.
http://developer.android.com/reference/android/widget/ScrollView.html
A ListView is very specifically designed to hold lists, where items typically look the same (or at least follow a pattern, e.g. section headings). ListView is also designed to connect to a data source of some sort, SQLite, array, content provider etc. ListView can scale to handle enormous numbers of list items.
http://developer.android.com/resources/tutorials/views/hello-listview.html
If you have data you need to show in a list, use a ListView. If you just need scrolling content, then a ScrollView is probbaly enough.
ListView:-
In ListView You can manage layout of items in xml easily that you want to display in list.
You are required to tell the adapter ho many item you want in your display list.
You can design for both homogenous as well as heterogenous views depending on your requirement by overrifing getItemViewType() method of Adapter.
In ListView items in list are created according to screen size. i.e How many items can appear on screen are created additional views(items) are created when list is scrolled at runtime. The views that are displayed once are cached when they move out of screen and when list is scrolled back to previous state the same views are displayed but this time view are not created rather they are fetched from cache.
ScrollView :-
Cache concept is not applicable with ScrollView.
All views are created at once when they come to screen and are not cached when they move out of screen while scrolling. They are present in memory(main) that may lead to memory leak because the number of objects created are not being destroyed by garbage collector since they are being referenced untill you are on same page.
Although you can create both homogenous as well as heterogenous views. If there are more items to be displayed in your list it would be tedious to manage the layout whether you are designing in xml or creating dynamically using Java code.
It is preferable to use scrollview if you have a single page that does not contain list of items e.g registration form, reservation form but that view is larger than the screen size then put ScrollView as parent view also keep in mind that ScrollView can have only one direct child layout/view.
ScrollView simply places its contents in a scrollable container, you can edit it's contents only by adding views to it.
ListView is a class that uses an adapter which handles creating the views for your data objects, you only need to edit the data, and the layout modifications are done automatically by the adapter.
ScrollView should be used when you have a screen (ex: a form with multiple fields) that do not fit into one screen on small devices, as such scrollview offers the user the possibility to scroll down.
ListView should be used when representing sets of data.
You can read about these at http://developer.android.com/guide/index.html
A ListView is backed by an Adapter, which contains a DataSource. This allows you to easily display data in rows.
A ScrollView allows you to put content inside of it, and if the content exceeds the size of the ScrollView, it will allow the user to scroll.
They both have their uses, but it depends on what you are trying to do.
Since an image worth a thousand words, here are perfect real life examples:
Listview is like the Kijiji app
Scrollview is like the EBay app
Also, see a scrollview like a billboard or a wall, where you can put bunch of different stuff on it.
And a listview is more like a result page: results are all of same nature, therefore they fit perfectly in a listview. Like a contacts list: they all share the same structure; phone number name address, etc....
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.