溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

圖片縮放

發(fā)布時間:2020-07-03 15:01:23 來源:網絡 閱讀:313 作者:jiangguocui 欄目:開發(fā)技術

要實現圖片的縮放,首先要判斷是否有兩個觸摸點,

然后要獲得兩個觸摸點的當前的距離,還有設置上一次兩觸摸點的距離。

如果當前距離減去上一次的距離大于5,圖片則是放大,

如果上一次的距離減去當前距離大于5,圖片則是縮小,

case MotionEvent.ACTION_MOVE:

//移動圖片

/*FrameLayout.LayoutParams lp=(android.widget.FrameLayout.LayoutParams) v1.getLayoutParams();

lp.leftMargin=(int) e.getX();

lp.topMargin=(int) e.getY();

v1.setLayoutParams(lp);*/

//縮放圖片

if(e.getPointerCount()>=2){//如果兩個點的時候才求距離

float offsetx=e.getX(0)-e.getX(1);

float offsety=e.getY(0)-e.getY(1);

current=(float) Math.sqrt(offsetx*offsetx+offsety*offsety);

if(lastdistance<0){

lastdistance=current;

}else{

if(lastdistance-current>5){//縮小

FrameLayout.LayoutParams lp=(android.widget.FrameLayout.LayoutParams) v1.getLayoutParams();

lp.width=(int) (v1.getWidth()*0.9);

lp.height=(int) (v1.getHeight()*0.9);

v1.setLayoutParams(lp);

lastdistance=current;

}else if(current-lastdistance>5){//放大

FrameLayout.LayoutParams lp=(android.widget.FrameLayout.LayoutParams) v1.getLayoutParams();

lp.width=(int) (v1.getWidth()*1.1);

lp.height=(int) (v1.getHeight()*1.1);

v1.setLayoutParams(lp);

lastdistance=current;

}

}

}

break;


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI