【达内课程】手势滑动

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
    从左至右滑动
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010356768/article/details/80691863
文章标签: 手势滑动
个人分类: 达内课程
上一篇JAVA中正则表达式的二次转义
下一篇添加依赖出现 Unable to resolve dependency for:xxx的报错
想对作者说点什么? 我来说一句

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

关闭
关闭
关闭