Get MotionEvent.getRawX/getRawY of other pointers
Indeed, the API doesn't allow to do this, but you can compute it. Try that :
public boolean onTouch(final View v, final MotionEvent event) {
int rawX, rawY;
final int actionIndex = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
final int location[] = { 0, 0 };
v.getLocationOnScreen(location);
rawX = (int) event.getX(actionIndex) + location[0];
rawY = (int) event.getY(actionIndex) + location[1];
}
MotionEvent GetY() and getX() return incorrect values
Try using getRawX()
and getRawY()
instead of getX()
and getY()
.
getRawX (getRawY) issue
You are not doing it correctly. The parameter to pass into "getX" and "getY" is the finger index. Pass in 0 for the first finger, 1 for the second, etc. The following is useful for dumping the relevant information in a motion event.
private void dumpEvent(MotionEvent event) {
String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
"POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
StringBuilder sb = new StringBuilder();
int action = event.getAction();
int actionCode = action & MotionEvent.ACTION_MASK;
sb.append("event ACTION_" ).append(names[actionCode]);
if (actionCode == MotionEvent.ACTION_POINTER_DOWN
|| actionCode == MotionEvent.ACTION_POINTER_UP) {
sb.append("(pid " ).append(
action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
sb.append(")" );
}
sb.append("[" );
for (int i = 0; i < event.getPointerCount(); i++) {
sb.append("#" ).append(i);
sb.append("(pid " ).append(event.getPointerId(i));
sb.append(")=" ).append((int) event.getX(i));
sb.append("," ).append((int) event.getY(i));
if (i + 1 < event.getPointerCount())
sb.append(";" );
}
sb.append("]" );
Log.d(TAG, sb.toString());
}
Related Topics
How to Use a Library Project in Android Studio
Stop Scrollview from Auto-Scrolling to an Edittext
Signing My Android Application as System App
How to Remove White Underline in a Searchview Widget in Toolbar Android
Export The Contacts as Vcf File
Isvalidfragment Android API 19
Android Httpsurlconnection Eofexception
When Should I Do Certain Sqlite Operations on Another Thread(Not The Main Thread)
How to Enable Night Mode Programmatically
Firebase Console: How to Specify Click_Action for Notifications
Supporting Amazon and Android Market (Google Play) Links Inside Application
How to Call a Wcf Service Using Ksoap2 on Android
Custom Listview Fast Scrollbar in Android
How to Set Proxysettings and Proxyproperties on Android Wi-Fi Connection Using Java
Detecting Webview Error and Show Message