is there a way to lock the vertical scrolling of a ListView while scrolling an item which is a ViewPager? Or perhaps change the horizontal scrolling sensitivity of the ViewPager?
Thanks.
LAST EDIT
Here is my updated solution. Thanks for your replies Masoud Dadashi, your comments finally made me came up with a solution to my problem.
Here is my custom ListView class:
public class FolderListView extends ListView {
private float xDistance, yDistance, lastX, lastY;
// If built programmatically
public FolderListView(Context context) {
super(context);
// init();
}
// This example uses this method since being built from XML
public FolderListView(Context context, AttributeSet attrs) {
super(context, attrs);
// init();
}
// Build from XML layout
public FolderListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// init();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance)
return false;
}
return super.onInterceptTouchEvent(ev);
}
}
A simple solution is to create your own subclass of ViewPager that has a private boolean flag, isPagingEnabled . Then override the onTouchEvent and onInterceptTouchEvent methods. If isPagingEnabled equals true invoke the super method, otherwise return .
There is no built in way to disable swiping between pages of a ViewPager, what's required is an extension of ViewPager that overrides onTouchEvent and onInterceptTouchEvent to prevent the swiping action. To make it more generalised we can add a method setSwipePagingEnabled to enable/disable swiping between pages.
yes there is. create another customListView class extended from ListView and override its dispatchTouchEvent event handler like this:
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
if(ev.getAction()==MotionEvent.ACTION_MOVE)
return true;
return super.dispatchTouchEvent(ev);
}
then use this customListView instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With