我在MotionEvent类中遇到某种错误。
我有以下代码(仅用于获取指针位置):
float currentX0 = currentEvent.getX(currentIndex0);
float currentY0 = currentEvent.getY(currentIndex0);
float currentX1 = currentEvent.getX(currentIndex1);
float currentY1 = currentEvent.getY(currentIndex1);
其中currentEvent
是MotionEvent的实例。
仅当按比例缩放视图(执行该事件)时,获得的值才有效。
x = 1, y = 1
-工作正常 x = 3, y = 3
-工作正常 x = 1, y = 1.8
这样的小差异也工作正常 然而,像x = 1, y = 3
这样的差异会使指针值变得疯狂。 下面的指针值
x0 | y0 | x1 | y1
161.75629 | 166.02393 | -45.33643 | -7.61890
-11.86243 | 171.64899 | 128.53229 | -13.03632
162.54289 | 165.93451 | -45.47116 | -7.62537
-12.89105 | 171.88275 | 128.67145 | -13.06726
162.47267 | 166.13928 | -45.96663 | -7.74609
-12.51083 | 171.78931 | 129.54721 | -13.10638
162.81955 | 166.08453 | -46.12793 | -7.71875
-12.21097 | 171.85919 | 128.87845 | -13.24426
162.12735 | 166.71558 | -45.84099 | -7.82043
-11.77496 | 172.07104 | 128.86295 | -13.49707
162.18164 | 166.45728 | -45.81119 | -8.04248
-13.66464 | 171.82251 | 128.85971 | -13.48279
161.31250 | 166.18518 | -46.41249 | -7.91089
-14.06512 | 171.52637 | 128.73209 | -13.28387
161.47177 | 166.27606 | -46.36593 | -7.67633
-13.29575 | 171.29504 | 128.72192 | -13.22839
161.80443 | 165.99536 | -46.73647 | -7.43408
-13.57471 | 171.38422 | 128.70450 | -13.05377
161.18291 | 166.10242 | -46.07407 | -7.50183
-13.41876 | 171.36401 | 128.55240 | -13.03125
161.68098 | 165.53320 | -45.95214 | -7.48248
-13.67712 | 171.17920 | 128.49545 | -12.79791
161.01393 | 165.88690 | -45.90237 | -7.28442
-12.87860 | 171.21973 | 128.40631 | -12.81409
160.77586 | 165.90747 | -45.60313 | -7.31372
-13.13638 | 171.14270 | 128.32498 | -12.79681
160.81250 | 165.86353 | -45.63880 | -7.26862
-13.13165 | 171.10944 | 128.31921 | -12.76257
162.30196 | 165.59668 | -45.61549 | -7.23676
如您所见,值在波动。更准确地说,值在多点触摸手势的焦点附近振荡。
值得注意的是,我正在根据这些坐标旋转视图。