相关疑难解决方法(0)

两个活动之间的Android共享元素转换不起作用

在我的应用程序中,我正在尝试使用新引入的活动之间的元素共享.如果共享元素具有固定位置(例如android:layout_gravity="top"),则一切都像魅力一样,但是当视图锚定时问题就出现了.

我的第一个活动看起来像这样:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:auto="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        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.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/play_all"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="24dp"/>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我的第二项活动是这样的

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:auto="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:elevation="10dp"
        android:src="@drawable/ic_action_play"
        auto:layout_anchor="@+id/appbar"
        android:transitionName="fab_button"
        auto:layout_anchorGravity="bottom|right" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="192dp">
        ...
    </android.support.design.widget.AppBarLayout>

    ...

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我使用的代码如下:

Intent intent = ...;
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, view, "fab_button");
startActivity(intent, options.toBundle());
Run Code Online (Sandbox Code Playgroud)

如果我使用layout_anchorlayout_anchorGravity属性,两个FAB之间的过渡完成没有动画.如果第二个FAB具有固定位置,则它可以完美地工作.我究竟做错了什么?

android floating-action-button android-design-library

20
推荐指数
2
解决办法
2565
查看次数