how to Shared element transition from a fragment to an activity

后端 未结 4 606
轮回少年
轮回少年 2020-12-16 17:26

I have three fragments inside a ViewPager in an activity, I want to achieve shared element transition from one of the fragments to another activity. The transition is from a

4条回答
  •  清酒与你
    2020-12-16 17:30

    I think using Pairs as below:

     Pair[] pairs = new Pair[1];
                pairs[0] = new Pair(tvArtifacts, "itemTrans");
                ActivityOptions options = null;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                    options = ActivityOptions.makeSceneTransitionAnimation(getActivity(), pairs);
                }
    
                Intent i = new Intent(getActivity(), ItemDetailActivity.class);
                i.putExtra("item_name", "item 2");
                if (options != null) {
                    startActivity(i, options.toBundle());
                } else {
                    startActivity(i);
                }
    

    This worked for me! Thanks..

提交回复
热议问题