Android 更流畅的捏合缩放?
我已经为我的捏缩放功能的“实现”编写了自己的代码,它可以工作,但它根本不用户友好。通常非常零星,而且总体来说一点也不漂亮。我想知道你们中是否有人可以帮助我,也许是一种更简单的方法或不同的方法。也许使用 GestureListener 但我不知道如何使用它。任何帮助将不胜感激。
下面是我当前的代码:
public boolean onTouchEvent(MotionEvent event) {
float cr, cr2 = 0.0f;
cx = new float[2];
cy = new float[2];
float zx;
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN: {
break;
}
case MotionEvent.ACTION_POINTER_DOWN: {
break;
}
case MotionEvent.ACTION_MOVE: {
for (int i = 0; i<event.getPointerCount(); i++) {
if (run == true) { //see if it is the first time running program and set orig to the scale / screen res
Orig = scale * 800; //800 = screen res
}
cx[i] = event.getX(i); //get x and y for each finger
cy[i] = event.getY(i);
cr = (cx[0] - cx[1])*(cx[0] - cx[1]) + (cy[0] - cy[1])*(cy[0] - cy[1]); //get the distance between pointers
cr2 = FloatMath.sqrt(cr);
if (run == true) {
scale = cr2/800;
run = false;
}
else {
if (scale >= 550.0f) {
scale = 1.0f;
}
if (scale <= 0.0f) {
scale = 1.0f;
}
nScale = Orig/cr2;
scale = nScale * 0.5f;
}
}}
这可能根本不是执行此操作的最佳方法。取多个事件的平均值会得到更好的响应吗?
谢谢
I have made my own code for my 'implementation' of a pinch zoom feature and it works, but it is not user-friendly at all. Often very sporadic and in general not pretty at all. I was wondering if any of you could help me out, maybe a easier way or different approach. Perhaps using the GestureListener I'm not sure how to use it though. Any help would be appreciative.
Below is my current code:
public boolean onTouchEvent(MotionEvent event) {
float cr, cr2 = 0.0f;
cx = new float[2];
cy = new float[2];
float zx;
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN: {
break;
}
case MotionEvent.ACTION_POINTER_DOWN: {
break;
}
case MotionEvent.ACTION_MOVE: {
for (int i = 0; i<event.getPointerCount(); i++) {
if (run == true) { //see if it is the first time running program and set orig to the scale / screen res
Orig = scale * 800; //800 = screen res
}
cx[i] = event.getX(i); //get x and y for each finger
cy[i] = event.getY(i);
cr = (cx[0] - cx[1])*(cx[0] - cx[1]) + (cy[0] - cy[1])*(cy[0] - cy[1]); //get the distance between pointers
cr2 = FloatMath.sqrt(cr);
if (run == true) {
scale = cr2/800;
run = false;
}
else {
if (scale >= 550.0f) {
scale = 1.0f;
}
if (scale <= 0.0f) {
scale = 1.0f;
}
nScale = Orig/cr2;
scale = nScale * 0.5f;
}
}}
This is probably not the best way to do this at all. Would taking the average over several events give better responses?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅索尼爱立信开发者世界上的缩放支持教程,希望他们能为您提供一些线索。
See the zoom support tutorials on Sony Ericsson Developer World, hope they can give you some clue.