资源描述:
《Android多点触摸》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、HowtouseMulti-touchinAndroid2Thisisthefirstinaseriesofarticlesondevelopingmulti-touchapplicationswithAndroid2.x.ItisexcerptedfromChapter11ofthebook“Hello,Android!(3rdedition)”,availableinbetanowatThePragmaticProgrammers.Introducingmulti-touchMulti-touchissimplyanextensionofthereg
2、ulartouch-screenuserinterface,usingtwoormorefingersinsteadofone.We’veusedsingle-fingergesturesbefore,althoughwedidn’tcallitthat.InChapter4welettheusertouchatileintheSudokugameinordertochangeit.That’scalleda“tap”gesture.Anothergestureiscalled“drag”.That’swhereyouholdonefingeronthe
3、screenandmoveitaround,causingthecontentunderyourfingertoscroll.Tap,drag,andafewothersingle-fingeredgestureshavealwaysbeensupportedinAndroid.ButduetothepopularityoftheAppleiPhone,earlyAndroiduserssufferedfromakindofgestureenvy.TheiPhonesupportedmulti-touch,inparticularthe“pinchzoo
4、m”gesture.Threecommontouchgestures:a)tap,b)drag,andc)pinchzoom.(ImagecourtesyofGestureWorks.com)Withpinchzoom,youplacetwofingersonthescreenandsqueezethemtogethertomaketheitemyou’reviewingsmaller,orpullthemaparttomakeitbigger.BeforeAndroid2.0youhadtouseaclunkyzoomcontrolwithiconst
5、hatyoupressedtozoominandout(forexamplethesetBuiltInZoomControls()intheMyMapexample).Butthankstoitsnewmulti-touchsupport,youcannowpinchtozoomonAndroidtoo!Aslongastheapplicationsupportsit,ofcourse.Note:IfyoutrytoruntheexampleinthischapteronAndroid1.5or1.6,itwillcrashbecausethosever
6、sionsdonotsupportmulti-touch.We’lllearnhowtoworkaroundthatinchapter13,“WriteOnce,TestEverywhere”.Warning:Multi-bugsaheadMulti-touch,asimplementedoncurrentAndroidphonesisextremelybuggy.Infactit’ssobuggythatitbordersontheunusable.TheAPIroutinelyreportsinvalidorimpossibledatapoints,
7、especiallyduringthetransitionfromonefingertotwofingersonthescreenandvice-versa.Onthedeveloperforumsyoucanfindcomplaintsoffingersgettingswapped,xandyaxesflipping,andmultiplefingerssometimesbeingtreatedasone.Withalotoftrialanderror,Iwasabletogettheexampleinthischapterworkingbecause
8、thegestureitimplementsissosimple.UntilGo