Android View动画视图口吃

时间:2015-01-19 12:35:33

标签: android animation

我有一个带有一些视图init的LinearLayout(透明灰色背景,TextView,View,...)。我想用slideIn,slideOut动画(在xml中定义)来动画化。 第一个动画完成后,第二个动画开始。在动画期间,您可以看到口吃。 我几乎检查了所有帖子,没有人帮忙! 没有复杂的代码。 从xml加载动画并开始动画。如果第一个停止,另一个停止。

这是我的视图布局,它将动画:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/overlay_deal"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="@dimen/spacing_small">

        <TextView
            android:id="@+id/text_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="2dp"
            android:textAppearance="@style/TextAp.Dyn.Fixed.Small"
            android:textColor="@color/white"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/text_header_promo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:text="@string/Corporate_Label_Title"
            android:textAppearance="@style/TextAp.Dyn.Fixed.Small"
            android:textColor="@color/white" />
    </LinearLayout>

    <View
        android:id="@+id/text_header_underline"
        android:layout_width="match_parent"
        android:layout_height="3dp" />

    <View
        android:id="@+id/underline_spacer"
        android:layout_width="match_parent"
        android:layout_height="15dp"
        android:background="@color/white"
        android:visibility="gone" />
</LinearLayout>

This is the code:

private void initAnimations(Context context,final View defaultMoodBannerView){

    final int slideInFromTopAnimationId = R.anim.slide_in_from_top;
    final int slideOutToTopAnimationId = R.anim.slide_out_to_top;

    final int animationDuration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime);

    animationDefaultMoodBannerChangeToCorporate = AnimationUtils.loadAnimation(context, slideOutToTopAnimationId);
    animationDefaultMoodBannerChangeToCorporate.setDuration(animationDuration);

    animationDefaultMoodBannerSlideInFromTop = AnimationUtils.loadAnimation(context, slideInFromTopAnimationId);
    animationDefaultMoodBannerSlideInFromTop.setDuration(animationDuration);

    animationCorporateMoodBannerChangeToDefault = AnimationUtils.loadAnimation(context, slideOutToTopAnimationId);
    animationCorporateMoodBannerChangeToDefault.setDuration(animationDuration);

    animationCorporateMoodBannerSlideInFromTop = AnimationUtils.loadAnimation(context, slideInFromTopAnimationId);
    animationCorporateMoodBannerSlideInFromTop.setDuration(animationDuration);

    animationCorporateMoodBannerSlideOutToTop = AnimationUtils.loadAnimation(context, slideOutToTopAnimationId);
    animationCorporateMoodBannerSlideOutToTop.setDuration(animationDuration);

    animationDefaultMoodBannerChangeToCorporate.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (corporateMoodBannerView != null) {
                if (defaultMoodBannerView != null) {
                    defaultMoodBannerView.setVisibility(View.GONE);
                }
                corporateMoodBannerView.setVisibility(View.VISIBLE);
                corporateMoodBannerView.startAnimation(animationDefaultMoodBannerSlideInFromTop);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    animationCorporateMoodBannerChangeToDefault.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (defaultMoodBannerView != null) {
                if (corporateMoodBannerView != null) {
                    corporateMoodBannerView.setVisibility(View.GONE);
                }

                defaultMoodBannerView.setVisibility(View.VISIBLE);
                defaultMoodBannerView.startAnimation(animationDefaultMoodBannerSlideInFromTop);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

}

0 个答案:

没有答案