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

7

我有一个像下面图片中的布局

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中的一个图块时,我会用另一个ContentFragment片段替换HostFragment,该片段应该共享被点击的图片。我通过应用共享元素转换来实现这一点,如下所示:

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中开始动画时,封面瓷砖的初始位置是错误的(请查看此屏幕截图视频)- 它具有不希望出现的底部偏移量。
从视觉上看,这个偏移量看起来等于HostFragment的选项卡栏的高度。你们有什么想法可以避免这个偏移吗?
值得一提的是,所有RecyclerView的子项都具有唯一的transitionNames。

你尝试过隔离问题,看看是否是由于CoordinatorLayout引起的吗?这是一个有缺陷的类,所以我建议在一个简单的FrameLayout父容器中运行动画,看看问题是否仍然存在。 - Paul Burke
2
@PaulBurke 感谢您的关注。我对最新的支持和设计库中出现的问题感到有些沮丧。因此,我决定暂时使用另一种动画效果。我需要一些时间来冷静下来,然后再尝试分离这个问题。 - sergej shafarenka
1个回答

1
我知道这个问题很古老,但我一直在处理类似的问题。
最后,我所要做的就是将父视图xml中的android:clipChildren标志更改为false。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接