if (getDistance(x, mStartX, y, mStartY) < moveRange) {
updateViewPosition();
} else {
//斜率
float k = (y - mStartY) / (x - mStartX);
double rx;
double ry;
rx = Math.sqrt(moveRange * moveRange / (k * k + 1));
if ((x - mStartX) < 0) {
rx = -rx;
}
ry = k * rx;
wmParams.x = (int) (rx + 700);
wmParams.y = (int) (ry + 1900);
//回调sin,cos
listener.onSpeakListener(ry / radius, rx / radius);
wm.updateViewLayout(this, wmParams); //刷新显示
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Activity接收参数
customeMovebutton.setOnSpeakListener(new CustomeMovebutton.OnSpeakListener() {
@Override
public void onSpeakListener(double sin, double cos) {
speedLat = -speed * sin;
speedLon = speed * cos;
}
});
————————————————