在我的应用程序中,我尝试使用新引入的元素共享功能在不同活动之间共享元素。如果共享的元素具有固定位置(例如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>
我的第二个活动长这样
<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>
我使用的代码如下:
Intent intent = ...;
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, view, "fab_button");
startActivity(intent, options.toBundle());
如果我使用layout_anchor
和layout_anchorGravity
属性,两个浮动操作按钮之间的转换将没有任何动画效果。如果第二个浮动操作按钮是固定位置的,则可以完美地工作。我做错了什么?