Android共享元素过渡,起始位置错误

标签 android android-animation android-transitions

我的布局如下图所示

enter image description here

其中橙色框架是 HostFragment 是这样构建的:

<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/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:titleMarginStart="68dp"
                />

            <de.halfbit.audiopie.ui.common.views.SlidingTabs
                android:id="@id/tabs"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:slidingTabsIndicatorColor="@color/accent"
                />

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

    <android.support.v4.view.ViewPager
        android:id="@id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

蓝色框架是一个子ItemsFragment,里面有一个RecyclerView

当我点击 RecyclerView 中的图 block 时,我将 HostFragment 替换为另一个 ContentFragment fragment ,该 fragment 假定共享点击的图像。我通过应用共享元素转换来实现,如下所示:

FragmentManager fm = getChildFragmentManager();
Fragment fragment = ContentFragment.newInstance();

AutoTransition autoTransition = new AutoTransition();
autoTransition.setDuration(3000);
fragment.setSharedElementEnterTransition(autoTransition);

fm.beginTransaction()
    .replace(R.id.library, fragment)
    .addSharedElement(view, "cover")
    .commit();

除了一件事它工作正常:当动画在 ContentFragment 中开始时,封面图 block 的初始位置是错误的 (see this screen cast video) - 它具有不需要的底部偏移。

在视觉上,此偏移量看起来等于 HostFragment 的选项卡栏的高度。你们知道如何避免这种偏移吗?

还值得一提的是,所有 RecyclerView 的 子级都有唯一的 transitionNames

最佳答案

我知道这个问题很古老,但我一直在与类似的问题作斗争。

最后我所要做的就是将父 View xml 中的 android:clipChildren 标志更改为 false。

关于Android共享元素过渡,起始位置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33356053/

相关文章:

android - 共享元素转换 Android 不工作

java - Realm:如果应用程序及其库之一使用 Realm 并设置(两者)defaultConfiguration,那么 defaultInstance 是什么?

java - 如何创建特定尺寸的android studio布局文件夹?获取无效配置时出错 '1080x2340'

android - 非线性 Activity 过渡动画

android - Android L 中的 RecyclerView ItemAnimator 故障

android - 动画android View 的高度

android - 是否有适用于 Android 的 Hero iOS 版本?

java - 如何针对不同版本的客户端代码进行自动化测试

android - 如何将图像从 url 加载到小部件的 android 远程 View 中

android - 动画移除 fragment