android viewflipper项目的顺序

android viewflipper项目的顺序,android,viewflipper,items,Android,Viewflipper,Items,我有一个viewflipper,XML中有三个直接的child 1、2、3。但它们显示为1,3,2。 我认为我的fling代码有问题,如下所述 但是我不能理解这个概念 <ViewFlipper android:id="@+id/view_flipper" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout

我有一个viewflipper,XML中有三个直接的child 1、2、3。但它们显示为1,3,2。 我认为我的fling代码有问题,如下所述

但是我不能理解这个概念

 <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>

我的密码

        @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;
}
@覆盖
公共布尔onFling(运动事件e1、运动事件e2、浮点速度X、,
浮动速度y){
试一试{
如果(e1.getX()>e2.getX()和&Math.abs(e1.getX()-e2.getX())>swip\u MIN\u DISTANCE和&Math.abs(velocityX)>swip\u THRESHOLD\u VELOCITY){
//mVf.setOutAnimation(animFlipOutPrevious);
//mVf.设定无生气(动物前一种);
mVf.showPrevious();
}else if(e1.getX()滑动距离和数学abs(velocityX)>滑动阈值速度){
//mVf.setOutAnimation(动画FlipOutNext);
//mVf.setInAnimation(animfilipinext);
mVf.showNext();
}
UpdateTos(mVf.getDisplayedChild());
}捕获(例外e){
//没什么
}
返回true;
}

提前感谢

将mVf.showPrevious()与mVf.showNext()交换,将mVf.showNext()与mVf.showPrevious()交换 在你的onFling方法中,它应该解决你的问题

下面是对解决方案的解释。 案例1: 其中e1.getX()>e2.getX()表示从右向左滑动(显示下一页)。这里您应该使用mVf.showNext() 案例2:
其中e1.getX()Thx进行快速重播,它解决了这个问题。现在我觉得很尴尬,因为我错过了那一个:)