关于Android中ImageView使用Matrix.setScale的用法注意事项

image.png

Matrix.setScale包含两个函数,分别是:

1、setScale(float sx, float sy)

Set the matrix to scale by sx and sy.

2、setScale(float sx, float sy, float px, float py)

Set the matrix to scale by sx and sy, with a pivot point at (px, py).


如何正确的实现缩放,建议如下操作:

(cx,cy)为触摸的中心点;lasScaleFactor为上次的缩放因子,scaleFactor为本次的缩放因子。

(rdx,rdy)为图片左上角坐标。

1、缩放:mMatrix.setScale(scaleFactor, scaleFactor);

2、平移:mMatrix.postTranslate(cx-scalefactor/lasScaleFactor*(cx-rdx), cy-scalefactor/lasScaleFactor*(cy-rdy));

3、mImageview.setImageMatrix(mMatrix);


这样即可。


为了解决缩放前后以及过程中出现图片移动,可以考虑在TouchDown事件发生后,所有手指抬起之前,主要是发生了多指触摸,单独的平移操作即禁用。


(点击率:1249)

评论

昵称

 聚享站 | 培训学校管理系统 | 惊觉社区 | 杭州同城分类信息 | 
这视界--www.deepvast.com这视界 合作联系QQ:362733019

浙ICP备17017888号