GestureOverlayView隐藏子视图的事件

时间:2013-10-01 10:22:23

标签: android gesture

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

1 个答案:

答案 0 :(得分:0)

在我看来这不起作用,因为你将监听器附加到你不使用的颜色选择器上。

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

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

稍后您将创建一个完全不同的视图gestureOverlayView,之前的视图根本不会显示。