Get the multi-Touch point core code:
Get the number and position of touch points
public boolean OnTouch (View V, motionevent event) {switch (event. Getaction()) {case Motionevent. ACTION_down:system. out. println("Down"); Break;Case Motionevent. ACTION_up:system. out. println("Number of touch points:"+event. Getpointercount());System. out. println(String. Format("x1:%f y1:%f x2:%f y2:%f", event. GetX(0), Event. GetY(0), Event. GetX(1), Event. GetY(1)));System. out. println("Up");Framelayout. LayoutparamsLP = (layoutparams) image. Getlayoutparams();Lp. LeftMargin= (int) event. GetX();Lp. RightMargin= (int) event. GetY();Image. Setlayoutparams(LP);System. out. println(String. Format("X:%f,y:%f", event. GetX(), Event. GetY())); Break;Case Motionevent. ACTION_move:system. out. println("Move"); Break;
Two finger zoom Android robot Pictures
Frame. Setontouchlistener(New Ontouchlistener () {@Override public boolean onTouch (View V, motionevent event) { Switch (event. Getaction()) {case Motionevent. ACTION_down:system. out. println("Down"); Break;Case Motionevent. ACTION_up:if (Event. Getpointercount() >=2) {Float OffsetX = Event. GetX(0)-event. GetX(1);Float OffsetY = Event. GetY(0)-event. GetY(1);Currentdistance = (float) Math. sqrt(offsetx*offsetx+offsety*offsety);if (Lastdisatance <0) {lastdisatance = Currentdistance;}else {if (Currentdistance-lastdisatance >5) {Framelayout. LayoutparamsLP = (layoutparams) image. Getlayoutparams();Lp. Width= (int) (1.1F*image. GetWidth());Lp. Height= (int) (1.1F*image. GetHeight());Image. Setlayoutparams(LP);Lastdisatance = Currentdistance;}else if (Lastdisatance-currentdistance >5) {Framelayout. LayoutparamsLP = (layoutparams) image. Getlayoutparams();Lp. Width= (int) (0.9F*image. GetWidth());Lp. Height= (int) (0.9F*image. GetHeight());Image. Setlayoutparams(LP);Lastdisatance = Currentdistance;}}}//System. out. println("Number of touch points:"+event. Getpointercount());System. out. println(String. Format("x1:%f y1:%f x2:%f y2:%f", event. GetX(0), Event. GetY(0), Event. GetX(1), Event. GetY(1)));System. out. println("Up");Framelayout. LayoutparamsLP = (layoutparams) image. Getlayoutparams();Lp. LeftMargin= (int) event. GetX();Lp. RightMargin= (int) event. GetY();Image. Setlayoutparams(LP);System. out. println(String. Format("X:%f,y:%f", event. GetX(), Event. GetY())); Break;Case Motionevent. ACTION_move:system. out. println("Move"); Break;Default Break;} return False;} });
Android Multi-Touch zoom picture-android Learning Journey (iv)