来自活动的SharedElement的Android Show Dialog Fragment

时间:2017-03-16 09:03:13

标签: android android-activity translation dialogfragment

我想显示一个Dialogfragment,它出现在我的Activity的SharedElement中。我尝试过SharedElementTransition并且无效。这是代码:

FragmentManager fm = this.getSupportFragmentManager();
AddHistoryFragment mAddHistoryFragment = new AddHistoryFragment();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    mAddHistoryFragment.setSharedElementReturnTransition(TransitionInflater.from(
                        this).inflateTransition(R.transition.change_image_trans));
    mAddHistoryFragment.setExitTransition(TransitionInflater.from(
                        this).inflateTransition(android.R.transition.fade));

    mAddHistoryFragment.setSharedElementEnterTransition(TransitionInflater.from(
                        this).inflateTransition(R.transition.change_image_trans));
    mAddHistoryFragment.setEnterTransition(TransitionInflater.from(
                        this).inflateTransition(android.R.transition.fade));
   fm.beginTransaction().add(mAddHistoryFragment,"add History")
                        .addSharedElement(ivAddExpense, ivAddExpense.getTransitionName()).commit();
   }else {
        mAddHistoryFragment.show(fm, "History");
   }

谢谢

1 个答案:

答案 0 :(得分:2)

可悲的是,它不会起作用。共享元素转换仅适用于replace片段事务,但DialogFragment.show()使用add事务。

另外,看到这个问题,也许它的解决方案对你有用 Android - Shared Element Transition In Dialog