Android共享元素转换,错误的起始位置

ser*_*nka 7 android android-animation android-transitions

我有一个如下图所示的布局

在此输入图像描述

其中橙色框架是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>
Run Code Online (Sandbox Code Playgroud)

而蓝框是一个ItemsFragment带有a 的孩子RecyclerView.

当我点击我的瓷砖RecyclerView替换HostFragment另一个ContentFragment片段时,假设共享点击的图像.我是通过应用共享元素转换来实现的,如下所示:

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();
Run Code Online (Sandbox Code Playgroud)

它可以正常工作:当ContentFragment中的动画开始时,封面图块的初始位置是错误的(参见此屏幕投射视频) - 它具有不希望的底部偏移.

在视觉上,此偏移量看起来等于标签栏的高度HostFragment.你们有没有想过如何避免这种偏移?

值得一提的是,所有RecyclerView's孩子都有独特之处transitionNames.

小智 1

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

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