如何将共享元素从片段过渡到活动 [英] how to Shared element transition from a fragment to an activity

查看:100
本文介绍了如何将共享元素从片段过渡到活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个活动的ViewPager内部有三个片段,我想实现从一个片段到另一个活动的共享元素过渡.过渡来自回收者视图,该视图位于片段中,而片段中则是Viewpager内,Activity内 活动-> ViewPager->片段-> Recyclerview

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 recycler view which is inside a fragment which is inside a viewpager which is inside an Activity Activity->ViewPager->Fragment->Recyclerview

我在每个地方的互联网上都进行了搜索,但是只有关于共享元素从一个片段到另一个片段以及从一个活动到另一个活动的过渡信息. 从片段到活动的过渡没有任何内容

I have searched each every places internet but there are info only about shared element transition from one fragment to another and one activity to another. There is no content about transition from fragment to activity

holder.poster.setTransitionName("posterX");
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) con,holder.poster,holder.poster.getTransitionName());
            Log.e("Animation", "Success");
            //startActivity((Activity) con,intent,options.toBundle());
            c.startActivity(intent,options.toBundle());

使用上述代码后,第二个活动将启动,但看不到任何内容,例如,第二个活动包含一个FAB,当单击youtube时将启动该活动. 我知道FAB在哪里,所以当我盲目单击时,youtube可以正确启动,但是在第二次活动中什么都看不到

On using the above code the second activity is launched but nothing is visible, For example the second activity contains a FAB which when clicked youtube is launched. I know where the FAB is so when i click blindly, youtube launched correctly but nothing is visible in second activity

D/ViewRootImpl: changeCanvasOpacity: opaque=true

它是其中之一. 我认为这一定是问题所在!

Its one of the logcats. I think this must be the problem!!

推荐答案

我遇到了同样的问题,找不到任何对不起的东西,但是也许您应该重新考虑为什么在可能的情况下为什么需要片段与活动"关系处理片段到片段"或活动到活动"关系.

I had the same problem, I couldn't find anything that helps sorry, but maybe you should reconsider why would you need a Fragment to Activity relation when you could work with a Fragment to Fragment or Activity to Activity relation.

我已经解决了将代码更改为片段与片段"关系的问题,并且有很多有关该文档的文档和示例

I've solved my problem that way changing my code to a Fragment to Fragment relation and there is plenty documentation and examples about that Shared Element Transitions

这篇关于如何将共享元素从片段过渡到活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆