我想在手机上刷手时填写进度条。 我想我应该使用滚动方法或onfling方法。但我怎么能理解我刷了多少? 我使用这段代码:
@Override
public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
try {
if(e1.getX()- e2.getX()> min_dist) {
Toast.makeText(getBaseContext(), "Left Swipe", Toast.LENGTH_SHORT).show();
}
else if (e2.getX()- e1.getX()> min_dist ) {
Toast.makeText(getBaseContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
}
if(e1.getY() -e2.getY() > min_dist ) {
Toast.makeText(getBaseContext(), "Swipe up", Toast.LENGTH_SHORT).show();
}
else if (e2.getY() - e1.getY()> min_dist ) {
Toast.makeText(getBaseContext(), "Swipe down", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
// nothing
}
return true;
}
但是,当我将手x向y滑动时,有时会说e1.getX() - e2.getX() = 440
有时会说
e1.getX() - e2.getX() =200
我不明白。 我想担心我可以在刷卡的同时填写进度条吗?