我想在 Android Wear(我使用的是 Samsung Gear Live)上捕捉触摸事件来绘制触摸轨迹。我尝试将 onTouch 事件和 onGenericMotionEvent 事件捕获为以下代码,但该事件仅触发一次,或者有时在我在屏幕上滑动时不会发生。我需要更多的触摸事件(从左向右滑动时至少需要 5 到 6 个事件)来绘制轨迹。如何在 Android Wear 屏幕上捕获足够的触摸事件?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
ViewGroup container = (ViewGroup) findViewById(R.id.container);
container.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
String s = "";
s += "action=" + event.getAction();
s += ", X=" + event.getX();
s += ", Y=" + event.getY();
Log.d(TAG, s);
return false;
}
});
container.setOnGenericMotionListener(new View.OnGenericMotionListener() {
@Override
public boolean onGenericMotion(View view, MotionEvent event) {
String s = "";
s += "action=" + event.getAction();
s += ", X=" + event.getX();
s += ", Y=" + event.getY();
Log.d(TAG, s);
return false;
}
});
}
});
}