Android custom horizontal drag tremble -


i created class should used allow user horizontally relocate view sliding finger on bar, code this

public class dragger implements view.ontouchlistener {   private view todrag;   private point startdragpoint;   private int offset;   public dragger (view bar, view todragg){     todrag = todragg;     dragging = false;     bar.setontouchlistener(this);   }   public boolean ontouch(view v, motionevent evt) {     switch (evt.getaction()) {         case motionevent.action_down:           startdragpoint = new point((int) evt.getx(), (int) evt.gety());           offset = startdragpoint.x - (int) todrag.getx();         break;         case motionevent.action_move:           int currentx = (int)evt.getx();           log.d("log","currentx=" + currentx);           todrag.setx(currentx-offset);         break;         case motionevent.action_up:             int difference = (startdragpoint.x-offset)-(int)todrag.getx();             if(difference<-125){               ((viewmanager) todrag.getparent()).removeview(todrag);             }else{                 todrag.setx(startdragpoint.x-offset);             }             dragging = false;     }     return true;   } } 

in oncreate of main activity use calling constructor this:

new dragger(baritem,itemtodrag); 

it apparently work, seems tremble lot while dragging... tried understand why work strangely, added log instruction in action_move, , result that... if move right pixel pixel currentx instead of increasing 1 decrease of variable number, 10, 18 , when go next pixel turn normal increasing of 1... doesen't make sense... ideas on how fix it?

first guess: there other fingers on device causes move work erratically

second guess: right seem using setx method more movex , specifying increment function moves. might not designed for

third point: move function acts finicky. run (as in whenever there pointer on screen) , depends on position of finger. recommend changing function make step

suggestion make action move step function takes 1 value

case motionevent.action_move:       int currentx = (int)evt.getx();       if(abs(currentx)>10)currentx=(int) currentx/5;       todrag.setx(currentx-offset); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -