我正在尝试为我的应用程序实现多点触控放大和缩小功能.我的应用程序是查看图像的幻灯片.我试图通过http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-6-implementing-the-链接实现多点触控缩放功能. pinch-zoom-gesture/1847,它实际上是一个很好但我需要控制放大和缩小.即我想实现缩放的最大和最小限制.任何人都可以帮我解决这个问题.还要提前感谢调查这个问题.
在我对缩放图像视图的搜索和编码中,我遇到了一个小部件,它完全是Gallery app缩放功能的副本,易于使用.虽然我已经设计了自己的变焦Iamgeview但后来我发现重新发明下面的轮子并不是很好的事情是链接
礼貌:Alessandro Crugnola
http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/
当然,你需要改变这个部分:
else if (mode == ZOOM) {
float newDist = spacing(event);
Log.d(TAG, "newDist=" + newDist);
if (newDist > 10f) {
matrix.set(savedMatrix);
float scale = newDist / oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
Run Code Online (Sandbox Code Playgroud)
至
else if (mode == ZOOM) {
float newDist = spacing(event);
Log.d(TAG, "newDist=" + newDist);
if (newDist > 10f) {
matrix.set(savedMatrix);
float scale = newDist / oldDist;
// check scale is not too big or two small
float newScale = scale*mCurrentScale;
if (newScale > 10) {
return false;
} else if (newScale < 0.1) {
return false;
}
mCurrentScale = newScale;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
Run Code Online (Sandbox Code Playgroud)
并且还mCurrentScale为您的活动添加一个变量以记住当前的比例,如下所示:
public class Touch extends Activity implements OnTouchListener {
// These matrices will be used to move and zoom image
Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
// this is the new variable added
float mCurrentScale = 1.0f;
Run Code Online (Sandbox Code Playgroud)
...
| 归档时间: |
|
| 查看次数: |
12811 次 |
| 最近记录: |