【发布时间】:2011-09-03 12:53:28
【问题描述】:
我有一个在屏幕上绘制 2 个圆圈的应用。绘制后,我可以移动其中一个圆圈并将其放置在我想要的位置。有没有办法确定我触摸了哪个圆圈,以便我可以移动那个特定的圆圈?目前我只能在 centerX centerY 的坐标上移动圆。
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
if(xyFound == false) {
centreX = (int) ev.getX()-70;
centreY = (int) ev.getY()-70;
xyFound = true;
} else {
centreA = (int) ev.getX()-70;
centreB = (int) ev.getY()-70;
abFound = true;
bothCirclesInPlace = true;
invalidate();
}
}
case MotionEvent.ACTION_MOVE: {
if(xyFound == false){
centreX = (int) ev.getX()-70;
centreY = (int) ev.getY()-70;
xyFound = true;
}else{
centreA = (int) ev.getX()-70;
centreB = (int) ev.getY()-70;
bothCirclesInPlace = true;
invalidate();
} break;
}
.
[更新1]
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
float circ1Val = centreX + centreY;
float circ2Val = centreA + centreB;
float choice1 = circ1Val - (ev.getX() + ev.getY());
float choice2 = circ2Val - (ev.getX() + ev.getY());
float circleToBeMoved = choice1 < choice2 ? ;
。 我不确定计算每个圆圈与触摸事件之间距离的最佳方法。这是在正确的路线上吗?或者,还有更好的方法?谢谢
【问题讨论】:
标签: android bitmap touch-event