I have two listviews, but they don\'t scroll. How do I correct this?
Here is my layout.xml
You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView
Putting ListView
inside a ScrollView
is never inspired.
But if you want your posted XML-like behavior, there're 3 options to me:
Remove ScrollView
: Removing your ScrollView
, you may give the ListView
s some specific size with respect to the total layout (either specific dp
or layout_weight
).
Replace ListView
s with LinearLayout
s: You may add the list-items by iterating through the item-list and add each item-view to the respective LinearLayout
by inflating the view & setting the respective data (string, image etc.)
If you really need to put your ListView
s inside the ScrollView
, you must make your ListView
s non-scrollable (Which is practically the same as the solution 2 above, but with ListView
codes), otherwise the layout won't function as you expect.
To make a ListView
non-scrollable, you may read this SO post, where the precise solution to me is like the one below:
listView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
By default ListView is scrollable. Do not put ScrollView to the ListView
Practically its not good to do. But if you want to do like this, just make listview's height fixed to wrap_content.
android:layout_height="wrap_content"
Listview so have inbuild scrolling capabilities. So you can not use listview inside scrollview. Encapsulate it in any other layout like LinearLayout or RelativeLayout.
Never put ListView
in ScrollView
. ListView
itself is scrollable.