欢迎来到天天文库
浏览记录
ID:40530178
大小:33.00 KB
页数:4页
时间:2019-08-04
《android 图片多点触碰放大缩小》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、publicclassImageZoomActivityextendsActivityimplementsOnTouchListener{privatestaticfinalStringTAG="Touch";//ThesematriceswillbeusedtomoveandzoomimageMatrixmatrix=newMatrix();MatrixsavedMatrix=newMatrix();//Wecanbeinoneofthese3statesstaticfinalintNONE=0;staticfinalintDRAG=1;staticfinalintZOOM=2;i
2、ntmode=NONE;//RemembersomethingsforzoomingPointFstart=newPointF();PointFmid=newPointF();floatoldDist=1f;privateImageViewview;privatebooleankeyUpDown=false;privateinttimer=0;/*(non-Javadoc)*@seeandroid.app.Activity#onCreate(android.os.Bundle)*/@OverridepublicvoidonCreate(BundlesavedInstanceState
3、){super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.touch);view=(ImageView)findViewById(R.id.imageView);Intentintent=getIntent();//Drawabledrawable=loadImgByFilePath(intent.getStringExtra("toZoom"));view.setImageURI(Uri.parse(intent.getStri
4、ngExtra("toZoom")));view.setOnTouchListener(this);}privateHandlerclickHandler=newHandler(){@OverridepublicvoidhandleMessage(Messagemsg){if(msg.what==0){keyUpDown=true;keyUpDownListener();}elseif(msg.what==1){keyUpDown=false;if(timer<=1)ImageZoomActivity.this.finish();elsetimer=0;}}};privateintk
5、eyUpDownListener(){newThread(){publicvoidrun(){while(keyUpDown){try{sleep(200);timer++;Log.d("info","timing:timer="+timer);}catch(InterruptedExceptione){e.printStackTrace();}}}}.start();returntimer;}@OverridepublicbooleanonTouch(Viewv,MotionEventevent){ImageViewview=(ImageView)v;//Dumptoucheven
6、ttolog//dumpEvent(event);//Handletoucheventshere...switch(event.getAction()&MotionEvent.ACTION_MASK){caseMotionEvent.ACTION_DOWN:savedMatrix.set(matrix);//設置初始點位置start.set(event.getX(),event.getY());Log.d(TAG,"mode=DRAG");clickHandler.sendEmptyMessage(0);mode=DRAG;break;caseMotionEvent.ACTION_P
7、OINTER_DOWN:oldDist=spacing(event);Log.d(TAG,"oldDist="+oldDist);if(oldDist>10f){savedMatrix.set(matrix);midPoint(mid,event);mode=ZOOM;Log.d(TAG,"mode=ZOOM");}break;caseMotionEvent.ACTION_UP:clickHandler.sendEmptyMessage(1);caseMo
此文档下载收益归作者所有