这是我的来源
private GestureDetector gesturedetector = null;private relativeLayout swipelayout;@Suppresslint("UseValueOf")@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw rootVIEw = inflater.inflate(R.layout.sTrada_menu_result_loadmore,container,false); swipelayout = (relativeLayout) rootVIEw.findVIEwByID(R.ID.swipelayout); gesturedetector = new GestureDetector(new MyGestureListener()); swipelayout.setontouchListener(new OntouchListener() { @OverrIDe public boolean ontouch(VIEw v,MotionEvent event) { gesturedetector.ontouchEvent(event); return true; } }); return rootVIEw;}public boolean dispatchtouchEvent(MotionEvent ev){ return gesturedetector.ontouchEvent(ev);}class MyGestureListener extends GestureDetector.SimpleOnGestureListener { private static final int SWIPE_MIN_disTANCE = 150; private static final int SWIPE_MAX_OFF_PATH = 100; private static final int SWIPE_THRESHolD_VELociTY = 100; @OverrIDe public boolean onFling(MotionEvent e1,MotionEvent e2,float veLocityX,float veLocityY) { float dX = e2.getX() - e1.getX(); float dY = e1.getY() - e2.getY(); if (Math.abs(dY) >= SWIPE_THRESHolD_VELociTY && Math.abs(veLocityX) >= SWIPE_THRESHolD_VELociTY && Math.abs(dX) >= SWIPE_MIN_disTANCE) { if (dX > 0) { Toast.makeText(getActivity(),"Right Swipe",Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getActivity(),"left Swipe",Toast.LENGTH_SHORT).show(); } return true; } return false; }}
我究竟做错了什么?如果有人知道解决方案,请帮助我
谢谢
我在一些工作项目中使用了这个代码,所以一切都应该正常.但请告诉我是否有遗漏并且不起作用.
yourrelativeLayout.setontouchListener(new OntouchListener() { int downX,upX; @OverrIDe public boolean ontouch(VIEw v,MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { downX = (int) event.getX(); Log.i("event.getX()"," downX " + downX); return true; } else if (event.getAction() == MotionEvent.ACTION_UP) { upX = (int) event.getX(); Log.i("event.getX()"," upX " + upX); if (upX - downX > 100) { // swipe right } else if (downX - upX > -100) { // swipe left } return true; } return false; } });@H_404_33@ 总结
以上是内存溢出为你收集整理的Android在RelativeLayout中左右滑动全部内容,希望文章能够帮你解决Android在RelativeLayout中左右滑动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)