I have a ListView
in a ScrollView
to show comments and I would like to do the following:
When the user swipes down, first the ScrollView
should fully scroll down as the list is at the bottom. Once it's fully down, the Listiew
should start scrolling.
Similarly, when the user is scrolling up, first the ListView
(order reversed here!) should scroll up, before the ScrollView
starts scrolling.
So far I have done the following:
listView.setOnTouchListener(new View.OnTouchListener() {
// Setting on Touch Listener for handling the touch inside ScrollView
@Override
public boolean onTouch(View v, MotionEvent event) {
// If going up but the list is already at up, return false indicating we did not consume it.
if(event.getAction() == MotionEvent.ACTION_UP) {
if (listView.getChildCount() == 0 && listView.getChildAt(0).getTop() == 0) {
Log.e("Listview", "At top!");
return false;
}
}
// Similar behaviour but when going down check if we are at the bottom.
if( event.getAction() == MotionEvent.ACTION_DOWN) {
if (listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1 &&
listView.getChildAt(listView.getChildCount() - 1).getBottom() <= listView.getHeight()) {
Log.e("Listview","At bottom!");
v.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
}
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
The logs trigger at the right moment, however the ScrollView
won't move even though I return false.
I also tried to add v.getParent().requestDisallowInterceptTouchEvent(false);
to the statements, but that did not work either.
How can I make it work?