Witam,
mam taki problem, w większości kursów o gestach pokazane jest jak ich używać na specjalnym przeznaczonym do tego polu - Android Developers Blog: Gestures on Android 1.6 . Ja mam cały ekran wypełniony buttonami i tekstem i chcę aby te gesty były wykonywalne na całym ekranie a nie na określonym obszarze. Jak pozmieniam w xmlu tak jak jest w kursie to wszystko zjeżdża mi się na samą górę i nie da się tego przesunąć.
Oto xml, obsługuje gesty, ale podczas działania aplikacji nie reaguje, ponieważ nie ma wyznaczonego do tego pola:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.gesture.GestureOverlayView
android:id="@+id/gestures"
android:eventsInterceptionEnabled="true"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/previous"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="@string/prev" />
<TextView
android:id="@+id/category"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/category"
android:gravity="center" />
<Button
android:id="@+id/next"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="@string/next" />
</LinearLayout>
<TextView
android:id="@+id/joke"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="@string/joke"
android:gravity="top"
android:layout_weight="1" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/favourite"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/fav" />
<Button
android:id="@+id/back"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/menu" />
</LinearLayout>
</LinearLayout>
Kod :
/wczytanie biblioteki gestów
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);
I metoda :
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
// We want at least one prediction
if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);
// We want at least some confidence in the result
if (prediction.score > 1.0) {
// Show the spell
Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show();
}
}
}