简体   繁体   中英

ViewFlipper With One Child (LinearLayout)

I' have a ViewFlipper, which contains one child only (a linearlayout), the problem I have is when I switch view's, it goes well and displays the next view and so on. But the animation doesn't goes smoothly, by that I mean that the current screen moves while next one shows up! In this case, the current screen gets removed and the next one slides in.

How can I make the current screen to slide away, and let the next one slide in while have one child in the ViewFlipper? I've been looking all over, can't find anything!

xml code:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout">
<ViewFlipper
    android:id="@+id/flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ListView
            android:id="@+id/dateView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="2"
        />
        <ListView
            android:id="@+id/myListView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
        />  
    </LinearLayout>
</ViewFlipper>

android code:

case MotionEvent.ACTION_UP:{
            currentX = event.getX();
            if (Math.abs(currentX - downXValue) >= v.getWidth()/5){
                if(currentX < downXValue){
                    calendar.add(Calendar.DAY_OF_MONTH, 1);
                    dateAdapter.notifyDataSetChanged();
                    todoAdapter.clear();
                    todoAdapter.notifyDataSetChanged();
                    vf.setInAnimation(v.getContext(), R.anim.push_left_in);
                    vf.setOutAnimation(v.getContext(), R.anim.push_left_out);
                    vf.showPrevious();
                }
                else{
                    calendar.add(Calendar.DAY_OF_MONTH, -1);
                    dateAdapter.notifyDataSetChanged();
                    todoAdapter.clear();
                    todoAdapter.notifyDataSetChanged();
                    vf.setInAnimation(v.getContext(), R.anim.push_right_in);
                    vf.setOutAnimation(v.getContext(), R.anim.push_right_out);   
                    vf.showNext();
                }   
            }
            break;
        }

Best regards!

Use a ViewSwitcher instead. Implement a ViewSwitcher.ViewFactory to provide the inside view (you can use a LayoutInflater with a layout xml), set it using ViewSwitcher.setFactory and use ViewSwitcher.getNextView and View.findViewById to find and set your components accordingly.

A ViewSwitcher is also a subclass of ViewAnimator so you can set the in/out animations and use showNext and showPrevious as you are already familiar with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM