android - how to make left right activity slider? -
any suggestions how make activity slider "slide left" , "slide right" typical image slider??
i tried with: (implements ontouchlistener)
public boolean ontouch(view v, motionevent event) { switch (event.getaction()) { case motionevent.action_down: { // code break; } case motionevent.action_up: { // code break; } case motionevent.action_move: { // code break; } } return true; }
but don't have left, right choice.
i don't need use buttons, need somethings image slider ipad2 activities customer app.
thanks
you need calculate own slide left , right movement
motionevent.action_up
a pressed gesture has finished, motion contains final release location intermediate points since last down or move event.
motionevent.action_down
a pressed gesture has started, motion contains initial starting location.
use ontouchevent()
, , calculate difference in x , difference in y user presses down , lifts up. use these values figure out direction of move.
float x1, x2, y1, y2; string direction; switch(event.getaction()) { case(motionevent.action_down): x1 = event.getx(); y1 = event.gety(); break; case(motionevent.action_up) { x2 = event.getx(); y2 = event.gety(); float differenceinx = x2-x1; float differenceiny = y2-y1; // use dx , dy determine direction if(math.abs(differenceinx) > math.abs(differenceiny)) { if(differenceinx > 0) direction = "right"; else direction = "left"; } else { if(differenceiny > 0) direction = "down"; else direction = "up"; } } }
Comments
Post a Comment