【问题标题】:Android shared element transition, wrong starting positionAndroid共享元素过渡,起始位置错误
【发布时间】:2015-10-26 21:34:01
【问题描述】:

我的布局如下图所示

橙色框是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

【问题讨论】:

  • 您是否尝试过隔离问题,看看是否是由CoordinatorLayout 引起的?这是一个有问题的类,所以我会尝试在一个简单的 FrameLayout 父级中运行动画,看看问题是否仍然存在。
  • @PaulBurke 感谢您的调查。我对最新的支持和设计库中的大量问题感到有些不安。所以我决定暂时使用另一种动画。我需要一些时间冷静下来,然后我会尝试隔离问题。

标签: android android-animation android-transitions


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-04
    • 2021-06-03
    • 1970-01-01
    • 2016-04-23
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多