ImageView手勢 雙擊可縮放

2022-07-26 09:48:07 字數 1790 閱讀 6186

import android.content.context;

import android.graphics.matrix;

import android.graphics.pointf;

import android.graphics.drawable.drawable;

import android.util.attributeset;

import android.util.log;

import android.view.motionevent;

import android.view.view;

import android.widget.imageview;

/*** imageview手勢/雙擊可縮放

* created on 2019/11/4.

*/public class gestureimageview extends imageview implements view.ontouchlistener

private int curmode=0;

private matrix matrix;

private pointf viewsize;

private pointf imagesize;

private pointf scalesize;

//記錄當前座標

private pointf curpoint;

private pointf originscale;

//0:寬度適應 1:高度適應

private int fitmode=0;

private pointf start;

private pointf center;

private float scaledoublezoom=0;

private pointf relativepoint;

private float doublefingerdistance=0;

long doubleclicktimespan=280;

long lastclicktime=0;

int rationzoomin=2;

public void gestureimageviewinit()

@override

protected void onmeasure(int widthmeasurespec, int heightmeasurespec) else

fitcenter();

}/**

* 使儲存在**

*/public void fitcenter()

if(curmode==zoommode.doublezoomin)

}break;

case motionevent.action_up:

//手指鬆開時觸發事件

break;

}//注意這裡return 的一定要是true 否則只會觸發按下事件

return true;

}/**

* 根據縮放因子縮放

* @param scale

*/public void setimagescale(pointf scale)

/*** 根據偏移量改變位置

* @param offset

*/public void setimagetranslation (pointf offset)

public static float getdoublefingerdistance (motionevent event)

}

支援手勢的ImageView庫

專案中有個需求,可以檢視配套資源。該配套資源可以是png,jpg,gif資源 在開發過程中遇到的問題 1.資源可以替換,位址是相同的 2.支援展示gif 方案public class photoviewactivity extends baseactivity final photoviewatta...

移動端禁用雙擊放大手勢

網上容易找到的方法之一就是在head標籤內定義頁面元資訊 meta viewport如下 copy expand 1 meta name viewport content width device width,initial scale 1.0,maximum scale 1.0,user scal...

Swift中新增雙擊手勢識別器

已經完成了單擊識別器,但無法弄清楚如何將該單擊識別器改為雙擊.import foundation import uikit class mainboardcontroller uiviewcontroller override func didreceivememorywarning func go...