我想知道如何在水平滚动视图中获取滚动方向,比如是向左还是向右滚动,我应该立即知道这一点,就像有类似onScrollChnageListener 之类的东西,并且有onLeftScroll或onRightScroll方法
问问题
2799 次
2 回答
2
你可以像下面这样找到它:
private GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener() {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(e1.getX() > e2.getX())
isScrollingTowardsLeft = true;
else
isScrollingTowardsLeft = false;
return false;
};
};
于 2013-03-04T16:11:28.710 回答
0
一点点逻辑对我有用。您可以简单地获取两个指针[firstPointerCurrentValue,firstPointerLastValue]
(......不要惊慌 firstPointer 是始终指向列表中第一个可见项的变量)并将它们匹配为新的和更新的值。
int firstPointerCurrentValue = 0;
int firstPointerLastValue = 0;
...........
lv.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView alv, int scrollState) {
checkValue(firstPointerCurrentValue, firstPointerLastValue);
firstPointerLastValue = firstPointerCurrentValue;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
firstPointerCurrentValue = firstVisibleItem;
}
});
……
boolean checkValue(int firstPointerCurrentValue, int firstPointerLastValue) {
if (firstPointerCurrentValue > firstPointerLastValue) {
Toast.makeText(getBaseContext(), "DOWN ", Toast.LENGTH_SHORT)
.show();
ab.hide();
} else if (firstPointerCurrentValue < firstPointerLastValue) {
Toast.makeText(getBaseContext(), "UP ",
Toast.LENGTH_SHORT).show();
} else {
// Toast.makeText(getBaseContext(), "No Move ", Toast.LENGTH_SHORT)
// .show();
}
return false;
}
于 2014-10-06T10:46:47.563 回答