I've searched around for solutions to this problem, and the only answer I can find seems to be "don't put a ListView into a ScrollView". I have yet to see any real explanation for why though. The only reason I can seem to find is that Google doesn't think you should want to do that. Well I do, so I did.
So the question is, how can you place a ListView into a ScrollView without it collapsing to its minimum height?
There's a built-in setting for it. On the ScrollView:
In Java,
Romain Guy explains it in depth here: http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
Using a
ListView
to make it not scroll is extremely expensive and goes against the whole purpose ofListView
. You should NOT do this. Just use aLinearLayout
instead.A solution I use is, to add all Content of the ScrollView (what should be above and under the listView) as headerView and footerView in the ListView.
So it works like, also the convertview is resued how it should be.
This is the only thing that worked for me:
on Lollipop onwards you can use
This enable or disable nested scrolling for this view if you need backwards compatibility with older version of the OS you'll have to use the RecyclerView.
We could not use two scrolling simulteniuosly.We will have get total length of ListView and expand listview with the total height .Then we can add ListView in ScrollView directly or using LinearLayout because ScrollView have directly one child . copy setListViewHeightBasedOnChildren(lv) method in your code and expand listview then you can use listview inside scrollview. \layout xml file
onCreate method in Activity class:
There are two issue when using a ListView inside a ScrollView.
1- ListView must fully expand to its children height. this ListView resolve this:
Divider height must be 0, use padding in rows instead.
2- The ListView consumes touch events so ScrollView can't be scrolled as usual. This ScrollView resolve this issue:
This is the best way I found to do the trick!