程序用Qt和android 结合写的 现在滑动关闭程序时发现不能完全关闭程序,请教android中有没有滑动关闭程序事件
onTouchEvent 监听滑动事件,在符合滑动条件的情况下 finish掉 不行吗?QT我没接触过 ,我只能说说我认为的方法了
安卓没有滑动关闭的事件,需要你自己去实现。
我不太清楚你的没有完全退出是什么意思,如果是Activity没有完全被销毁的话,那你需要重新管理你的Activity堆栈,在关闭程序的时候全部finish。
System.exit(0)可以强制停止进程(但是极个别机型可能会有兼容问题),但是并不推荐使用。
//假如你需要在滑动时关闭某项,可以在activity中的dispatcherTouchEvent()中处理
//全局变量
int mLastDownX,mLastDownY;
//重写dispatcherTouchEvent(){
switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
mLastDownX=(int)ev.getX();
mLastDownY=(int)ev.getY();
break;
case MotionEvent.ACTION_MOVE:
int moveX=(int)ev.getX();
int moveY=(int)ev.getY();
if(Math.abs(moveX-mLastDownX)>200){
//当滑动的距离大于200dp,执行以下操作
removeAction();//你的方法
}
break;
case MotionEvent.ACTION_UP:
break;
}
return super.dispatchTouchEvent(ev);
}