【发布时间】:2012-01-05 09:20:53
【问题描述】:
我想从 Android 应用程序中的模拟时钟设置时间。为此,我重写了 Analogclock.java 类并建立了 Ontouchevent 监听器。我按照 this method 和 this formula 从获得的坐标计算时针和分针之间的角度。现在我可以将手移到一个新的位置。我还可以从中获取针之间的新角度。这是相同的代码:
case MotionEvent.ACTION_MOVE:
x = (int)event.getX();
y = (int)event.getY();
double dx = x - minuteRect.centerX();
double dy = -(y - minuteRect.centerY());
double inRads = Math.atan2(dy,dx);
if (inRads < 0)
inRads = Math.abs(inRads);
else
inRads = 2*Math.PI - inRads;
double newDegree = Math.toDegrees(inRads);
if(isMove()){
setAngle(newDegree);
invalidate();
}
我现在想设置针移动的时间。 有什么方法可以从坐标或两个针之间的角度计算时间?
【问题讨论】: