开发者

Why the view goes all black before ViewFlipper starts to flip?

开发者 https://www.devze.com 2023-04-02 09:16 出处:网络
Problem: I have managed to get the ViewFlipper to work properly, sort of. But when ViewFlipper flips, the view blacks out first, then the next view slides in. Can somebody please tell me how can I pre

Problem: I have managed to get the ViewFlipper to work properly, sort of. But when ViewFlipper flips, the view blacks out first, then the next view slides in. Can somebody please tell me how can I prevent the screen from black out? Thank you.

Details: I'm doing a month calendar (in a Dialog), the us开发者_Python百科er can slide his finger across the screen to change month and year, when the new month's or year's calendar will side in. Before the animation starts, the program will first change the text in the view (e.g., changing the month/year lable, day numbers, etc.). Then it calls ViewFlipper.showNext() to perform the trick. However, the screen always goes black before the new calendar slides in. Is there any way to prevent it to be blacked out? Thank you!

// Set up the text in the new calendar before hand
setDateLabels();
// Now slide in the new calendar
ViewFlipper flipper = ((ViewFlipper)findViewById(R.id.flipper));
flipper.setInAnimation(AnimationUtils.loadAnimation(mActivity,
    (direction == 0) ? R.anim.slide_in_right :
    (direction == 1) ? R.anim.slide_in_left :
    (direction == 2) ? R.anim.slide_in_up : R.anim.slide_in_down
    ));
flipper.setOutAnimation(AnimationUtils.loadAnimation(mActivity, R.anim.hold));
flipper.showNext();

// This is the XML for the calendar
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/flipper"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:flipInterval="2000"
    android:layout_marginBottom="20dip" >
    <LinearLayout
        android:id="@+id/calendar"
        android:orientation="vertical"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
        <TextView
            android:background="#eaeaea"
            android:textSize="10pt"
            android:textColor="#0d0d0d"
            android:id="@+id/header"
            android:gravity="center"
            android:layout_width="fill_parent" 
            android:layout_height="46dp"/>
        <LinearLayout
            android:orientation="vertical"
            android:id="@+id/cells"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content">
            <!-- More TextViews will be added into this LinearLayout during run-time -->
        </LinearLayout>
    </LinearLayout>
</ViewFlipper>

// XML for slide_in_down.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate 
        android:fromYDelta="-100%p" 
        android:toYDelta="0"
        android:duration="@android:integer/config_shortAnimTime"/>
</set>

// XML for hold.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromXDelta="0" 
    android:toXDelta="0"
    android:duration="@android:integer/config_longAnimTime" />


You should call removeAllViews() before adding you own.

It seems that ViewFlipper adds some views when it is initialized.

0

精彩评论

暂无评论...
验证码 换一张
取 消