Another way to do this is to wrap the ListView
in whatever custom scrolling solution you've cooked up. If you simply set the height of the ListView
to be exactly as high as all the rows (using the list view's LayoutParams
), then it will act like a normal view and won't be able to scroll; therefore you can add it to another scroll view. The difficulty with this method is that you have to know the height of your list ahead of time, so you have to know the height of each row. Also, this will create all the rows at once and so you won't be able to take advantage of the view-recycling feature.
If you don't have an easy way of calculating the height ahead of time, you can trick the ListView
into doing it for you by overriding onMeasure
and giving it your own height spec:
// Calculate height of the entire list by providing a very large
// height hint. But do not use the highest 2 bits of this integer;
// those are reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);