滑動事件

private boolean touching;

private float touchTime;

private float distance =200;//滑動距離

private float time =1000;//按下抬起時間1s

private static float distanceLeft =200;//點(diǎn)擊位置距離屏幕左側(cè)的距離

private View.OnTouchListeneronTouchListener =new View.OnTouchListener() {

????????@Override

? ? ????public boolean onTouch(View v, MotionEvent event) {

????????????????switch (event.getAction()) {

????????????????????????case MotionEvent.ACTION_DOWN:

????????????????????????????????if (event.getX()){

????????????????????????????????????????touching =true;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? touchDownX = event.getX();

? ? ? ? ? ? ? ? ? ? ????????????????????touchTime = System.currentTimeMillis();

? ? ? ? ? ? ? ? ????????????????}else {

????????????????????????????????????????return false;

? ? ? ? ? ? ? ????????????????? }

????????????????????????break;

? ? ? ? ? ????????????? case MotionEvent.ACTION_UP:

????????????????????????????????if (!touching) {

????????????????????????????????????????return false;

????????????????????????????????}

? ? ? ? ? ? ? ? ????????????????if (System.currentTimeMillis() -touchTime >time) {

????????????????????????????????????????return false;

? ? ? ? ? ? ? ????????????????? }

????????????????????????????????if (event.getX() -touchDownX >distance) {

????????????????????????????????????????Log.i("wanan","滑動了");

? ? ? ? ? ? ? ? ????????????????}

????????????????????????????????touching =false;

????????????????????????break;

? ? ? ? ????????}

????????????????return true;

? ????? }

};

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容