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

时间:2015-10-26 21:34:02

标签: 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中的图块时,我将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();

除了一件事情之外它还可以正常工作:在ContentFragment中动画开始时封面图块的初始位置是错误的(see this screen cast video) - 它有不希望的底部偏移。

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

值得一提的是,所有RecyclerView's名儿童都有transitionNames个唯一身份。

1 个答案:

答案 0 :(得分:1)

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

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