听主屏幕的android触摸事件
问题描述:
大家好,
我正在开发一个应用程序,我想知道用户在Android手机的主屏幕上向下或向上滑动。基本上我想在用户在主屏幕上向上/向下滑动时执行一些操作。
我在网上搜索了很多但是没有找到答案是否可能或不。如果有可能,那么我可以从那里学习如何做到这一点。
预先感谢您的回复。*
Hello everyone,
I am developing an app in which I want to know when user swipe down or up on the home screen of the android mobile. Basically I want to perform some action whenever user swipe up/down on the home screen.
I search a lot on the web but found no answer whether it is possible or not. If it is possible then from where I can learn how to do this.
Thanks in advance for your kind reply.*
答
你需要覆盖 onTouchEvent():
You need to override onTouchEvent():
@Override
public void onTouchEvent(MotionEvent event) {
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
//do your stuff
break;
case MotionEvent.ACTION_UP:
//do your stuff
break;
}
}