android开发中为activity增加左右手势识别,如右滑关闭当前页面。
private void initgesture() {
mgesturedetector = new gesturedetector((ongesturelistener) this);
}
public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {
if (e1.getx() - e2.getx() > verticalmindistance && math.abs(velocityx) > minvelocity) {
// 切换activity
// intent intent = new intent(viewsnsactivity.this, updatestatusactivity.class);
// startactivity(intent);
//toast.maketext(this, "向左手势", toast.length_short).show();
} else if (e2.getx() - e1.getx() > verticalmindistance && math.abs(velocityx) > minvelocity) {
// 切换activity
// intent intent = new intent(viewsnsactivity.this, updatestatusactivity.class);
// startactivity(intent);
//toast.maketext(this, "向右手势", toast.length_short).show();
finish();
overridependingtransition(r.anim.push_right_in, r.anim.push_right_out);
}
return false;
}
@override
public void onlongpress(motionevent arg0) {
// todo auto-generated method stub
}
@override
public boolean onscroll(motionevent arg0, motionevent arg1, float arg2,
float arg3) {
// todo auto-generated method stub
return false;
}
@override
public void onshowpress(motionevent arg0) {
// todo auto-generated method stub
}
@override
public boolean onsingletapup(motionevent arg0) {
// todo auto-generated method stub
return false;
}
@override
public boolean ontouch(view v, motionevent event) {
// todo auto-generated method stub
return mgesturedetector.ontouchevent(event);
}
@override
public boolean ondown(motionevent arg0) {
// todo auto-generated method stub
return false;
}
@override
public boolean dispatchtouchevent(motionevent ev) {
mgesturedetector.ontouchevent(ev);
return super.dispatchtouchevent(ev);
}
push_right_in.xml
push_right_out.xml
如对本文有疑问, 点击进行留言回复!!
监听Android系统发出的插入SD卡并且已正确安装(识别)时发出的广播
RecyclerView三种常用效果的实现方法-android-kotlin
Android Studio app启动错误 Error running :Default Activity not found
Android Studio查看源码时出现Sources for ‘Android API 30 Platform’ not found 的 解决方法
网友评论