简体   繁体   English

共享元素从viewpager内的fragment recyclerview过渡到新活动?

[英]Shared element transition from fragment recyclerview inside viewpager to new activity?

I have a fragemnt with a recyclerView inside a viewPager of my MainActivity. 我的MainActivity的viewPager内有一个带有recyclerView的片段。 When an item image on the recyclerView is clicked, it opens a new activity with the shared element transition between the images. 单击recyclerView上的项目图像时,它将打开一个新活动,并在图像之间共享元素过渡。 Below is the the adapter for the recyclerView where i set up a onClickListener for the imageview inside the onBindViewHolder method... 下面是recyclerView的适配器,其中我在onBindViewHolder方法内为imageview设置了onClickListener ...

    //Adapter
     holder.image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    int position = holder.getAdapterPosition();

                    Intent intent = new Intent(mContext, NewActivity.class);

                    View sharedView = holder.Trendimage;

                    String transitionName = "transition";



            ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation((MainActivity)mContext, sharedView, transitionName);

   mContext.startActivity(intent, transitionActivityOptions.toBundle());



                 mContext.startActivity(intent);

            }
        });

The only problem is that when I click on an item it loads the new activity but the shared element enter animation does not work, however when i press the back button whilst on the new activity it works. 唯一的问题是,当我单击某个项目时,它将加载新的活动,但是共享元素输入的动画不起作用,但是当我在新活动中按下返回按钮时,它将起作用。

I have all the transitions name setup with the correct views, and the animations are included in my App theme style as required... 我拥有所有带有正确视图的过渡名称设置,并且动画根据需要包含在我的App主题样式中...

Any help on this would be great 任何帮助都会很棒

thank you 谢谢

您两次调用startActivity()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM