2012-03-17 5 views
0

Я работаю над viewFlipper с жестом. но этот жест не работает для перехода на следующую страницу.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> 
+0

"не работает" это совершенно бесполезно заявление. Вы можете увидеть «ViewFlipper», интегрированный с «GestureDetector» здесь: https://github.com/commonsguy/cwac-viewswiper – CommonsWare

ответ

0

Делают это так:

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(); 
       } 
      } 
     } 
     } 
    } 
};