android - why my MotionEvent.ACTION_BUTTON_PRESS did not call -
i have problem 1 of feature ontouchlistener. here code.
private float mprevx; private float mprevy; private static final string tag = "moveablebutton"; public mainactivity mainactivity; public moveablebutton(mainactivity mainactivity1) { mainactivity=mainactivity1; } @override public boolean ontouch(view view, motionevent motionevent) { float currx,curry; if (motionevent.getactionmasked()==motionevent.action_button_press) { log.d(tag, "ontouch: action_button_press"); intent = new intent(mainactivity, newactivity.class); mainactivity.startactivity(i); return true; } else if(motionevent.getactionmasked()==motionevent.action_down) { log.d(tag, "ontouch:action_down "); mprevx = motionevent.getx(); mprevy = motionevent.gety(); return true; } else if (motionevent.getactionmasked()==motionevent.action_move) { log.d(tag, "ontouch: action_move"); currx = motionevent.getrawx(); curry = motionevent.getrawy(); viewgroup.marginlayoutparams marginparams = new viewgroup.marginlayoutparams(view.getlayoutparams()); marginparams.setmargins((int)(currx - mprevx), (int)(curry - mprevy),0, 0); android.support.design.widget.coordinatorlayout.layoutparams layoutparams = new android.support.design.widget.coordinatorlayout.layoutparams(marginparams); view.setlayoutparams(layoutparams); return true; } return false; }
as can see want move button anywhere on screen(it works fine) wan when press button new activity called. motionevent.action_button_press never call. i have grid view 3 column in activity sorry poor english , in advance.
and in main activity
button fab = (button) findviewbyid(r.id.fab); moveablebutton buttonmove = new moveablebutton(this); fab.setontouchlistener(buttonmove);
Comments
Post a Comment