Android Multi-Touch zoom picture-android Learning Journey (iv)

Source: Internet
Author: User
Tags gety

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.