0

我已按照教程在我的 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 事件。任何帮助都会很棒!提前致谢。

4

1 回答 1

0

我认为这不起作用,因为您将侦听器附加到您不使用的颜色选择器。

在这一行中,您将侦听器附加到颜色选择器:

setContentView(R.layout.activity_lighting);
picker = (ColorPicker) findViewById(R.id.picker);
//Register the event handler for color changes
picker.setOnColorChangedListener(this);

稍后您将创建一个完全不同的视图gestureOverlayView,甚至根本没有显示以前的视图。

于 2013-10-02T20:10:44.573 回答