Android: How to mirror your touch? (visual pointer issue)
質問
I'm having a problem with my pointer for my tablet. I'm designing an art app and I'm trying to figure out how to mirror my movement (symmetry). Currently, if you touch the screen with your finger or stylus, an image (programmatically generated circle) is drawn and updates itself to wherever you move your finger/stylus. This works perfectly. But now I want to add two new features: Horizontal and vertical symmetry. So if you choose horizontal symmetry, another pointer will appear at the opposite X position, but along the same Y axis. So if you touch at 300x, 250y, and another pointer will show at -300x, 250y on the screen along with the original pointer. Now when I tried to apply and test it, I still only get the original pointer. Here is what I have so far:
rLO.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
// Hardware accelerated at runtime
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
cursor.x = (int)event.getX() - (cursor.radius / 2);
cursor.y = (int)event.getY() - (cursor.radius / 2);
cursor.onDraw(cursor.e);
rLO.addView(cursor);
if (hSym > 0) {
vSym = 0;
cursorH.x = -cursor.x;
cursorH.y = cursor.y;
cursorH.onDraw(cursorH.e);
rLO.addView(cursorH);
}
if (vSym > 0) {
hSym = 0;
cursorV.x = cursor.x;
cursorV.y = -cursor.y;
cursorV.onDraw(cursorV.e);
rLO.addView(cursorV);
}
break;
case MotionEvent.ACTION_MOVE:
// Hardware accelerated at runtime
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
//update pointer to new position of stylus/finger
cursor.x = (int)event.getRawX() - (cursor.radius / 2);
cursor.y = (int)event.getRawY() - (cursor.radius / 2);
rLO.removeView(cursor);
rLO.addView(cursor);
if (hSym > 0) {
cursorH.x = -cursor.x;
cursorH.y = cursor.y;
rLO.removeView(cursorH);
rLO.addView(cursorH);
}
if (vSym > 0) {
cursorV.x = cursor.x;
cursorV.y = -cursor.y;
rLO.removeView(cursorV);
rLO.addView(cursorV);
}
break;
case MotionEvent.ACTION_UP:
if (vSym > 0 || hSym > 0) {
rLO.removeView(cursorH);
rLO.removeView(cursorV);
}
rLO.removeView(cursor);
break;
} // end switch
NOTE: I used the word "cursor" in the code for "pointer." The pointer (cursor) is programmatically drawn from a different class which creates a circle.
正しい解決策はありません