viewFlipper с жестом - PullRequest
       40

viewFlipper с жестом

0 голосов
/ 17 марта 2012

Я работаю над viewFlipper с жестом.но жест не работает для перемещения на следующую страницу.

Я установил следующий и перед жестом как <,>, чтобы переместить следующую страницу, установив жесты.

Я не знаю, что не так с моим кодом.

AndroidViewFlipper

public class AndroidViewFlipperActivity extends Activity {

ViewFlipper page;
GestureLibrary mLibrary;
GestureOverlayView gestures;

AnimationSet animSetFlipInForeward;
AnimationSet animSetFlipOutForeward;
AnimationSet animSetFlipInBackward;
AnimationSet animSetFlipOutBackward;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    page = (ViewFlipper)findViewById(R.id.flipper);

    gestures = (GestureOverlayView) findViewById(R.id.gestures);
    gestures.addOnGesturePerformedListener(mListener);
    mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);



}

OnGesturePerformedListener mListener = new OnGesturePerformedListener() {
public void onGesturePerformed(GestureOverlayView overlay,Gesture gesture) {
        ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
        if (predictions.size() != 0) {
            Prediction prediction = predictions.get(0);
            String name = prediction.name;
            if (prediction.score > 1.0) {
                if(name.equals("prev")){
                    Log.i("tag","next1");
                    SwipeRight();
                }else if(name.equals("next")){
                    Log.e("tag","next2");
                    SwipeLeft();
                }
            }
        }
    }
};


private void SwipeRight(){
    page.setInAnimation(animSetFlipInBackward);
    page.setOutAnimation(animSetFlipOutBackward);
    page.showPrevious();
}

private void SwipeLeft(){
    page.setInAnimation(animSetFlipInForeward);
    page.setOutAnimation(animSetFlipOutForeward);
    page.showNext();
}
}   

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<ViewFlipper
    android:id="@+id/flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="@string/comment1" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="@string/comment2"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="@string/comment3"/>
    </LinearLayout>

  </ViewFlipper>
</LinearLayout>
</android.gesture.GestureOverlayView>

1 Ответ

0 голосов
/ 12 мая 2012

Сделай так:

OnGesturePerformedListener mListener = new OnGesturePerformedListener() {
public void onGesturePerformed(GestureOverlayView overlay,Gesture gesture) {
        ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
        for (Prediction prediction : predictions) {
        if (predictions.size() != 0) {
            String name = prediction.name;
            if (prediction.score > 1.0) {
                if(name.equals("prev")){
                    Log.i("tag","next1");
                    SwipeRight();
                }else if(name.equals("next")){
                    Log.e("tag","next2");
                    SwipeLeft();
                }
            }
        }
        }
    }
};
...