我正在使用带有 Android 3.2.1 的 Acer A500(电容屏)10" 平板电脑。我正在尝试捕捉手指触摸屏幕的区域以及屏幕上的压力量。我尝试过 Motionevent.getsize()我总是得到一个值 0。另外,Motionevent.getpressure() 总是给我一个值 1。
getX()、getY() 和 getEventTime() 等其他函数似乎工作正常。
我错过了什么吗?还有什么我需要做的吗?
任何帮助将不胜感激。
这是代码:
package com.mygroup.myapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class MultiTouchTest extends Activity implements OnTouchListener{
StringBuilder builder = new StringBuilder();
TextView textView;
float[] x = new float[10];
float[] y = new float[10];
double[] p = new double[10];
float[] s = new float[10];
long[] t = new long[10];
boolean[] touched = new boolean[10];
private void updateTextView(){
builder.setLength(0);
for (int i = 0; i < 10; i++){
builder.append(touched[i]);
builder.append(", ");
builder.append(x[i]);
builder.append(", ");
builder.append(y[i]);
builder.append(", pressure = ");
builder.append(p[i]);
builder.append(", size = ");
builder.append(s[i]);
builder.append(", time = ");
builder.append(t[i]);
builder.append("\n");
}
textView.setText(builder.toString());
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText("touch:");
textView.setOnTouchListener(this);
setContentView(textView);
}
//@Override
public boolean onTouch(View v, MotionEvent event){
int action = event.getAction() & MotionEvent.ACTION_MASK;
int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
MotionEvent.ACTION_POINTER_INDEX_SHIFT;
int pointerId = event.getPointerId(pointerIndex);
switch(action){
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
touched[pointerId] = true;
x[pointerId] = (int)event.getX(pointerIndex);
y[pointerId] = (int)event.getY(pointerIndex);
p[pointerId] = event.getPressure(pointerIndex);
s[pointerId] = event.getSize(pointerIndex);
t[pointerId] = event.getEventTime();
break;
...
}
updateTextView();
return true;
}
}