編輯:關於Android編程
private float currentDistance=0; private float lastDistance=-1; private FrameLayout frame; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); frame= (FrameLayout) findViewById(R.id.frame); final ImageView img= (ImageView) findViewById(R.id.img); frame.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()){ case MotionEvent.ACTION_DOWN: //觸摸按下 Log.i("MotionEvent","ACTION_DOWN"); break; } switch (event.getAction()){ case MotionEvent.ACTION_MOVE: //觸摸移動 Log.i("MotionEvent","ACTION_MOVE"); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) img.getLayoutParams(); if(event.getPointerCount()==1) { //單個觸摸點,並拖動圖片 System.out.println(String.format("X:%f,Y:%f", event.getX(), event.getY())); layoutParams.leftMargin = (int) event.getX()-10; layoutParams.topMargin = (int) event.getY()-10; img.setLayoutParams(layoutParams); } System.out.println("pointer count 觸摸點個數"+event.getPointerCount());//觸摸點個數 //多個觸摸點的坐標 //手勢放大縮小圖片 if (event.getPointerCount()>=2){ System.out.println(String.format("多個觸摸點的坐標X1:%f;Y1:%f", event.getX(0), event.getX(0))); 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(lastDistance<0){ lastDistance=currentDistance; }else { if(currentDistance-lastDistance>5){ //5px;有誤差 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) img.getLayoutParams(); System.out.println("放大"); lp.width= (int) (1.1f*img.getWidth()); lp.height=(int) (1.1f*img.getHeight()); img.setLayoutParams(lp); lastDistance=currentDistance; //放大 }else if (lastDistance-currentDistance>5){ lastDistance=currentDistance; //縮小 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) img.getLayoutParams(); lp.width= (int) (0.9f*img.getWidth()); lp.height=(int) (0.9f*img.getHeight()); img.setLayoutParams(lp); } } } break; } switch (event.getAction()){ case MotionEvent.ACTION_UP: //觸摸彈起 Log.i("MotionEvent","ACTION_UP"); break; } return true;//true:需要催發後續事件;false:不需要須發後續事件(只能執行一次) } }); }注意:
private float currentDistance=0; private float lastDistance=-1;
1.一些BB???上節我們為DrySister編寫了一個異步圖片加載緩存框架——SisterLoader(妹子加載器)成功的從網絡加載的圖片緩存到
本教程為通用教程 幾乎適合所有的安卓手機 希望可以幫到酷愛刷機的機油們!注意 不支持win8 支持win7/
在上一篇文章講了Android的Toast拓展,在原生Toast基礎上對顯示時長和顯示動畫做了二次封裝,強化了Toast的部分功能。也分析了對於二次封裝的ExToast設
首先弄懂怎麼設置adb wifi無線調試的功能,如下所示。1. 手機端開啟adb tcp連接端口:/$setprop service.adb.tcp.port 5555: