小编G_J*_*G_J的帖子

OnFling MotionEvent e1 null?

好.这件事几乎让我发疯.

几天前,我可以实现下面的代码,当我尝试向右或向左滑动时,toast成功调用.

但是,现在它无法调用,因为e1始终为null!

怎么会发生这种情况?我在模拟器上尝试此代码,但用户报告我,它也不适用于真实设备.

public class SwipeGestureListener extends GestureDetector.SimpleOnGestureListener{

    private static final int SWIPE_MIN_DISTANCE = 150;
    private static final int SWIPE_MAX_OFF_PATH = 100;

    private static final int SWIPE_THRESHOLD_VELOCITY = 100;
    private final Activity activity;
    protected MotionEvent mLastOnDownEvent = null;

    public SwipeGestureListener(Activity activity) {
        this.activity = activity;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        mLastOnDownEvent = e;
        System.out.println(e);
        return super.onDown(e);
    }

    @Override   
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        System.out.println(e1 + " " + e2);
        if (e1==null) …
Run Code Online (Sandbox Code Playgroud)

android

10
推荐指数
1
解决办法
4626
查看次数

标签 统计

android ×1