2014-03-27 68 views
0

我有一個在XML中有三個直接子元素1,2,3的viewflipper。但他們被顯示爲1,3,2。 我認爲我的一擲問題,如下所述 ViewFlipper order of itemsandroid viewflipper項目的順序

但我不能讓我的頭繞着這個概念。

<ViewFlipper 
    android:id="@+id/view_flipper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/ag" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:text="@string/how_to_use_text" 
      android:textAppearance="@android:style/TextAppearance.Medium" 
      android:textColor="@color/grey_text" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:text="@string/how_to_use_text1" 
      android:textAppearance="@android:style/TextAppearance.Medium" 
      android:textColor="@color/grey_text" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="15dp" 
      android:adjustViewBounds="true" 
      android:src="@drawable/tour_1" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/bg" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="45dp" 
      android:text="@string/how_to_use_text2" 
      android:textAppearance="@android:style/TextAppearance.Medium" 
      android:textColor="@color/grey_text" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="15dp" 
      android:adjustViewBounds="true" 
      android:src="@drawable/tour_2" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/cg" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="70dp" 
      android:text="@string/how_to_use_text3" 
      android:textAppearance="@android:style/TextAppearance.Medium" 
      android:textColor="@color/grey_text" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="15dp" 
      android:adjustViewBounds="true" 
      android:src="@drawable/tour_3" /> 
    </LinearLayout> 
</ViewFlipper> 

我onfling代碼

 @Override 
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 
     float velocityY) { 
    try { 
     if(e1.getX() > e2.getX() && Math.abs(e1.getX() - e2.getX()) > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 

      //mVf.setOutAnimation(animFlipOutPrevious); 
      //mVf.setInAnimation(animFlipInPrevious); 
      mVf.showPrevious(); 
     }else if (e1.getX() < e2.getX() && e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 

      // mVf.setOutAnimation(animFlipOutNext); 
      // mVf.setInAnimation(animFlipInNext); 
      mVf.showNext(); 
     } 
     updateDots(mVf.getDisplayedChild()); 
    } catch (Exception e) { 
     // nothing 
    } 
    return true; 
} 

在提前

回答

0

交匯處mVf.showPrevious()與mVf.showNext()和mVf.showNext()與mVf.showPrevious() 謝謝你的onFling方法,它應該可以解決你的問題。

以下是解決方案的說明。 案例1: 其中e1.getX()> e2.getX(),表示從右向左滑動(顯示下一頁)。這裏你應該使用mVf.showNext() Case2: 其中e1.getX()< e2.getX(),意味着從左向右滑動(顯示前一頁)。在這裏您應該使用mVf.showPrevious()

+0

Thx爲快速重播,它解決了問題。現在我感到尷尬,我錯過了一個:) – user3467481