【达内课程】手势滑动

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010356768/article/details/80691863
public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }

    private float downX;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d("Motion","ACTION_DOWN->"+event.getX()+","+event.getY());
                downX = event.getX();
                break;
            case MotionEvent.ACTION_UP:
                Log.d("Motion","ACTION_UP->"+event.getX()+","+event.getY());
                if(event.getX()-downX>60){
                    Log.d("Motion","从左至右滑动");
                }
                if(downX - event.getX()>60){
                    Log.d("Motion","从右至左滑动");
                }
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d("Motion","ACTION_MOVE->"+event.getX()+","+event.getY());
                break;
        }
        return false;
    }
}

观察日志

ACTION_DOWN->180.15381,301.11328
ACTION_MOVE->212.78,313.125
ACTION_MOVE->231.20656,313.125
......
ACTION_UP->445.00327,313.125
    从左至右滑动

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭