折叠视差滚动效果不会在淡入淡出时显示动画

时间:2018-03-16 08:02:14

标签: android android-collapsingtoolbarlayout

我正在使用CollapsingToolbarLayout来实现RecyclerView滚动的工具栏视差效果。以下代码是我在Activiti的onCreate方法中初始化工具栏的方法:

    setContentView(R.layout.activity_preview_recipe);
    Toolbar toolbar = findViewById(R.id.preview_recipe_toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null){
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if(inflater != null){
            mCustomToolBarView = inflater.inflate(R.layout.custom_action_bar, null);

            ActionBar.LayoutParams params = new ActionBar.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    Gravity.CENTER);

            actionBar.setCustomView(mCustomToolBarView, params);
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
            //set custom header view onClick action
            findViewById(R.id.home).setOnClickListener(view -> onBackPressed());
        }
    }

这是我的activity_preview_recipe.xml文件的内容,其中是CollapsingToolbarLayout

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/app_secondary"
>

<android.support.design.widget.AppBarLayout
    android:id="@+id/preview_recipe_app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/preview_recipe_collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/preview_recipe_max_height"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:animateLayoutChanges="true"
        app:titleEnabled="false"

        >

        <ImageView
            android:id="@+id/preview_recipe_top_img"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/preview_recipe_top_image"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:layout_collapseMode="parallax" />


        <TextView
            android:id="@+id/preview_recipe_credits"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|start"
            android:layout_marginEnd="@dimen/link_end_margin"
            android:padding="@dimen/space_default"
            android:autoLink="web"
            android:textColor="@android:color/white"
            android:layout_marginBottom="@dimen/preview_fab_bottom_margin"
            app:layout_collapseMode="pin"
            android:shadowColor="@android:color/black"
            android:shadowDx="-2"
            android:shadowDy="-2"
            android:shadowRadius="1"
            />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/preview_recipe_fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginEnd="@dimen/fab_margin"
            android:layout_marginBottom="@dimen/preview_fab_bottom_margin"
            app:backgroundTint="@color/colorPrimary"
            app:layout_collapseMode="pin" />

        <include layout="@layout/details_bar_layout"
            app:layout_collapseMode="pin"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/preview_recipe_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            app:layout_collapseMode="pin"
            android:background="@drawable/very_transparent_gradient"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_preview_recipe"/>

我在真实设备Android 6.0 API上进行了测试,并且对折叠(video)没有褪色效果。当我通过Android Studio模拟器模拟设备时,每次都会出现淡入淡出效果。 任何可能发生这种情况的想法都会有用。

1 个答案:

答案 0 :(得分:1)

您是否检查过测试设备上的动画 ON ?这可能是因为您的动画在开发者选项中 OFF

相关问题