Difference between ScrollView and ListView

2019-01-31 00:33发布

Can any one explain the difference between Scroll View and List View? When to use which one? And which one is more efficient?

6条回答
唯我独甜
2楼-- · 2019-01-31 00:33

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.

查看更多
疯言疯语
3楼-- · 2019-01-31 00:35

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....

查看更多
迷人小祖宗
4楼-- · 2019-01-31 00:42

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.

查看更多
疯言疯语
5楼-- · 2019-01-31 00:44

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.

查看更多
时光不老,我们不散
6楼-- · 2019-01-31 00:45

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

查看更多
SAY GOODBYE
7楼-- · 2019-01-31 00:50

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.

查看更多
登录 后发表回答