我在棒棒糖中进行了共享元素转换,但现在我的手机已升级到棉花糖,转换不再正常工作。从活动A到活动B的转换按预期工作,但是当按下返回到活动A时,转换工作,然后两个共享元素视图在屏幕上显示动画。
活动A:
Intent flashcardIntent = new Intent(this, FlashcardActivity.class);
flashcardIntent.putExtra(getString(R.string.study_id), flashcardSetId.toString());
flashcardIntent.putExtra(getString(R.string.flashcard_calling_activity), FlashcardActivity.SUBJECT_LIST);
ArrayList<Pair<View, String>> sharedElements = new ArrayList<>();
sharedElements.add(new Pair<View, String>(titleView, getString(R.string.transition_set_title)));
sharedElements.add(new Pair<View, String>(toolBar, getString(R.string.transition_toolbar)));
FlashcardSet set = FlashcardSetService.getInstance().getFlashcardSet(flashcardSetId);
if( set.isQuizletSet() )
{
sharedElements.add(new Pair<View, String>(quizletImage, getString(R.string.transition_quizlet_image)));
}
sharedElements.add(new Pair<View, String>(setCard, getString(R.string.transition_set_card)));
sharedElements.add(new Pair<View, String>(cardCount, getString(R.string.transition_card_count)));
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
// the context of the activity
this,
// For each shared element, add to this method a new Pair item,
// which contains the reference of the view we are transitioning *from*,
// and the value of the transitionName attribute
sharedElements.toArray(new Pair[sharedElements.size()])
);
ActivityCompat.startActivity(MainFlashcardSetListActivity.this, flashcardIntent, options.toBundle());
布局A:
<LinearLayout
android:id="@+id/test_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/test_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<ImageButton
android:id="@+id/delete_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete"
android:background="?android:selectableItemBackground"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="6dip"
android:layout_marginRight="6dip"/>
<com.bmb.kangaroo.views.NotePaperTextView
android:id="@+id/note_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginTop="16dip"
android:paddingLeft="14dip"
android:paddingRight="14dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:transitionName="@string/transition_set_title"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
<com.bmb.kangaroo.views.NotePaperTextView
android:id="@+id/note_list_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dip"
android:layout_marginTop="4dip"
android:ellipsize="end"
android:maxLines="5"
android:minLines="1"
android:paddingEnd="16dip"
android:paddingStart="16dip"
android:scrollHorizontally="false"
android:transitionName="@string/transition_card_count"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<ImageView
android:id="@+id/set_from_quizlet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/quizlet_icon"
android:layout_marginTop="12dip"
android:layout_gravity="end"
android:transitionName="@string/transition_quizlet_image"
android:visibility="invisible"
android:contentDescription="@string/from_quizlet"/>
</LinearLayout>
布局B:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/flashcard_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:transitionName="@string/transition_toolbar">
</android.support.v7.widget.Toolbar>
<com.bmb.kangaroo.views.NotePaperLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="14dip"
android:layout_marginLeft="14dip"
android:layout_marginStart="14dip"
android:transitionName="@string/transition_set_card"
android:layout_below="@id/flashcard_toolbar"/>
<com.bmb.kangaroo.views.NotePaperLayout
android:id="@+id/flashcard_set_title_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="14dip"
android:layout_marginLeft="14dip"
android:layout_marginStart="14dip"
android:layout_below="@id/flashcard_toolbar"
android:visibility="invisible">
<LinearLayout
android:id="@+id/test_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/test_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<ImageButton
android:id="@+id/delete_set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete"
android:background="?android:selectableItemBackground"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="6dip"
android:visibility="invisible"
android:layout_marginRight="6dip"/>
<com.bmb.kangaroo.views.NotePaperTextView
android:id="@+id/flashcard_set_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginTop="16dip"
android:paddingLeft="14dip"
android:paddingRight="14dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:transitionName="@string/transition_set_title"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
<com.bmb.kangaroo.views.NotePaperTextView
android:id="@+id/flashcard_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dip"
android:layout_marginTop="4dip"
android:ellipsize="end"
android:maxLines="5"
android:minLines="1"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:scrollHorizontally="false"
android:transitionName="@string/transition_card_count"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<ImageView
android:id="@+id/set_from_quizlet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/quizlet_icon"
android:layout_marginTop="12dip"
android:layout_gravity="end"
android:transitionName="@string/transition_quizlet_image"
android:contentDescription="@string/from_quizlet"
android:visibility="invisible"/>
</LinearLayout>
</com.bmb.kangaroo.views.NotePaperLayout>
<android.support.v4.view.ViewPager
android:id="@+id/flashcard_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/flashcard_set_title_card"
android:layout_gravity="center_vertical"/>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/flashcard_floating_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dip"
android:layout_marginEnd="16dip"
android:layout_marginRight="16dip"
res:fab_addButtonColorNormal="@color/accent_color"
res:fab_addButtonColorPressed="@color/accent_color_pressed"
res:fab_addButtonPlusIconColor="@android:color/white"
res:fab_labelStyle="@style/menu_labels_style">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/add_new_flashcard_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
res:fab_colorNormal="@color/accent_color"
res:fab_colorPressed="@color/accent_color_pressed"
res:fab_icon="@drawable/create"
res:fab_title="@string/add_flashcard"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/export_to_quizlet_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
res:fab_colorNormal="@color/accent_color"
res:fab_colorPressed="@color/accent_color_pressed"
res:fab_icon="@drawable/upload"
res:fab_title="@string/export_to_quizlet"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/share_flashcards_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
res:fab_colorNormal="@color/accent_color"
res:fab_colorPressed="@color/accent_color_pressed"
res:fab_icon="@drawable/share"
res:fab_title="@string/share_flashcards"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</RelativeLayout>
有没有人遇到过这种行为?或者注意代码有问题。