Why the ListView collapse when put in a ScrollView - android

I have read the all the answers here:How can I put a ListView into a ScrollView without it collapsing?But it seems no one cares why the ListView get collapsed when put in a ScrollView.I think something happens to the onMeasure() method but I'm not sure of it.So,does anyone have any idea?

Your aproach is not very good. As you did't describe your situation, i can't say exactly what you need. But anyway i will suggest to use Headers and footers instead of puttings scrollable listView in ScrollView. But if you need that anyway, i suggest to use RecyclerView and NestedScrollView instead, as it handles a lot of scrolling issues.
RecyclerView
NestedScrollView

Android doesn't support putting scrollable UI component as a child to other scrolable UI component. Since ListView is scrollable by default, that might be the problem. Hence, all the suggestions not to use ListView as a child to ScrollView

Related

When to use a Scroll View in Android?

My question is about best practices in Android in terms of using ScrollView to scroll other views and widgets. This is to know when to use a ScrollView to eliminate redundancy of scrolling if scrolling is possible in a given widget/view/layouts.
So I notice that there are instances where I don't really need to use ScrollView to make things scrollable. Few of the widgets/views/layouts that I know of are TextView and ListView. This is supported according to this documentation.
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
The TextView class also takes care of its own scrolling, so does not require a ScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.
My question is, are there other widgets/views/layouts that handles their own scrolling other than the two I have stated above and the documentation has. Maybe there are others that are scrollable or other methods to make things scrollable other than the default of some widgets and by using the ScrollView.
Preferred answers must be base on experience and documentation (other than what I've shown). Thanks in advance for any good answers.
WebView is one other class that does its own scrolling. My "best practice" advice is to use ScrollView to add scrolling to an arrangement (usually vertical) of fixed-size widgets. As you have noted, variable-sized widgets such as ListView provide their own scrolling.
if you read the official documentation you will find that tell you when not to use ScrollView:
You should never use a ScrollView with a ListView, ListView Because Takes Care of Its Own Vertical scrolling. Most importantly, doing all of the defeats esta Important optimizations in ListView for dealing with large lists, since it forces the ListView Effectively to displays its Entire list of items to fill up the container supplied by ScrollView infinite.
More information here.

Implementing listview with scrollable views and view caching

I'm on a research to design a ListView with horizontal scroll of views - something like in the facebook app.
I also need to implement a caching for the horizontally scrollable views.
Some of the options I can think of are:
Horizontal scroll view items.
A ViewPager which I understand is not quite good for this task.
What would be my way to go on this?
I've read some StackOverflow questions and am still researching but none of what I read so far also implement caching for the scrolled horizontal views.
Just use two RecyclerViews which are nested. The backing data is a two dimensional array as the layout is two-dimensional. The outer RecyclerView passes the data for the inner RecyclerView when the onBindViewHolder of the adapter is called. Additionally you may also use different layouts or ViewHolder respectively if the inner view consists only of a single item and does not require horizontal scrolling.
Some references about implementing RecyclerViews
Here: http://www.bignerdranch.com/blog/recyclerview-part-1-fundamentals-for-listview-experts/
Here: https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html
and here: https://developer.android.com/training/material/lists-cards.html
This will help you. You can use caching while scrolling. For example if you load images with horizontal scroll bar, you could use picasso library for catching and loading images.
Dont think big we have some library that will do what you want below listed some of them
https://github.com/sephiroth74/HorizontalVariableListView
https://github.com/EmirWeb/parchment
https://github.com/MeetMe/Android-HorizontalListView
any one this link will help you i belive
https://guides.codepath.com/android/Implementing-a-Horizontal-ListView-Guide
https://www.airpair.com/android/horizontal-image-galleries-android-studio

scrollView linearlayout and listview

I'm doing an android app, and I just want to have an scrollable layout, but inside of this layout I want to put some textView and 2 listView, and this is my problem, the listView.
I need to include this 2 listview on the layout and this is obligatory need to be scrollable, and I googling and all I found is negative.
how can I put 2 listview on scrollView?? is not possible? and if its right what can i do? Which is the alternative that I have? I really desesperated because I spend all day!!
con someone say me an example of this?
really thanks!
ListViews shouldn't be placed inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all get handled by the parent ScrollView. However you can add views you want to be scrolled to the ListView as headers or footers.

HorizontalScrollView with ListView--documentation bug?

The documentation for HorizontalScrollView has the following:
You should never use a
HorizontalScrollView with a ListView,
since ListView takes care of its own
scrolling. Most importantly, doing
this defeats all of the important
optimizations in ListView for dealing
with large lists, since it effectively
forces the ListView to display its
entire list of items to fill up the
infinite container supplied by
HorizontalScrollView.
The reasoning here seems to apply to a (vertically scrolling) ScrollView, since ListView also scrolls vertically. But ScrollView doesn't have any such caveat. Did Google put this warning in the wrong class, or am I not understanding something?
Looks like it is a bug indeed: http://code.google.com/p/android/issues/detail?id=2781

SimpleCursorAdapter within a ScrollView

I'm having abit of an issue and i'm not too sure how to go about solving it.
Essentially i have an activity which has a base xml layout of ScrollView and i want this activity to list some results from a Cursor. So i thought i'd use SimpleCursorAdapter... however when i got it all set up it appears that the ListView that the SimpleCursorAdapter goes into doesn't play nice being within another scrollable layout element.
I've sorta got it working programmically but i'd much rather use a ListAdapter as it will make each list entry look like a button and keep it inline with the design of the rest of the application and can handle the ids of each item and where to send the user upon clicking.
So my question is this: is there anyway to either make ListView show all the items such that it never needs to scroll, or can i change the ListView to something like a LinearLayout?
I hope that makes sense!
Any help / insight / ideas are welcome!
Cheers!
You can NEVER use a scroll view and a ListView together. Its a mess! and illogical as well.
Here are some of the approaches you can use:
Theres no screen big enough to show all the content of you listView you can try wrapping up your content but as I said it won't help as scroll view and list view don't work together. So you can either remove your or
If your list items are simple you can dynamically add your views to LinearLayout with specified location
Another tip I can give you is you can always use an relative layout and place your listView alignParentBottom="true" and emit the scrollView approach this will make you listview alwyas scrollable.
It doesn't really make sense to have a ListView inside a ScrollView at all. The ListView implements it's own scroll function so it should not be used in conjunction with a ScrollView anyway.
You should rethink your UI design.
I agree with Shardul; trying to put a listview with a scrollview will make it impossible to scroll. Have a look at the links below to see what you can accomplish with just a ListView -
a.
custom backgrounds info.
custom adapters

Categories

Resources