我已按照本教程在我的 Android 应用程序中创建了 GestureOverlayView。我的主视图中有一个颜色选择器,在它上面添加了手势覆盖。现在,叠加层工作正常,但是当叠加层位于顶部时,不会触发颜色选择器的颜色更改事件。这是活动的代码。
public class LightingActivity extends Activity implements OnColorChangedListener, OnGesturePerformedListener {
private ColorPicker picker;
private GestureLibrary gestureLib;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lighting);
picker = (ColorPicker) findViewById(R.id.picker);
//Register the event handler for color changes
picker.setOnColorChangedListener(this);
GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
View inflate = getLayoutInflater().inflate(R.layout.activity_lighting, null);
gestureOverlayView.addView(inflate);
gestureOverlayView.addOnGesturePerformedListener(this);
gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gestureLib.load()) {
finish();
}
setContentView(gestureOverlayView);
}
@Override
public void onColorChanged(int color) {
Toast.makeText(this, color, Toast.LENGTH_LONG).show();
}
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
for (Prediction prediction : predictions) {
if (prediction.score > 1.0) {
Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT)
.show();
}
}
}
}
我想要手势叠加,同时仍然能够触发颜色选择器视图的 onColorChanged 事件。任何帮助都会很棒!提前致谢。