1
我通過以下「標準」代碼成功實現了活動級別的自定義手勢。所以整個屏幕對手勢「起反應」。如何在ImageView上實現自定義手勢?
但是我希望能夠在特定的ImageView上完成自定義手勢。可能嗎?
感謝
public class DisplayMultiImageActivity extends Activity implements OnGesturePerformedListener {
GestureLibrary mLibrary;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_multiimage);
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);
}
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
if (predictions.size() > 0 && predictions.get(0).score > 1.0) {
String result = predictions.get(0).name;
if ("mycustomgesture".equalsIgnoreCase(result)) {
Toast.makeText(this, "Custom gesture detected!!", Toast.LENGTH_LONG).show();
}
}
}
}
你好Robbe,感謝您的anwser,它的工作!不過,我想我沒有用這個自定義手勢來解釋我的整個目標:我的佈局中有幾個圖像,手勢將用於選擇一個圖像:因此,我想知道用戶在哪個圖像上執行了手勢。你認爲這是可能的嗎?謝謝 – 2014-11-08 14:17:21
@ user3371862我已經更新了我的答案。 – Robbe 2014-11-08 17:34:19