[英]Android fragment transition on back navigation to previous fragment
I have 2 fragments the first contains a button which on clicked opens a fragment with a ListView
in it. 我有2个片段,第一个包含一个按钮,单击该按钮会打开一个包含ListView
的片段。 I have a shared element transition for the button to transition into the new fragment (root layout) but I would also like to have this transition in reverse (the list fragment contracts into the button again). 我有一个共享元素转换,按钮可以转换到新片段(根布局),但我也想反向转换(列表片段再次收缩到按钮中)。
However currently I detect the list item click and send an event to the Activity which pops the listview fragment off the backstack ( popBackStackImmediate()
) hence does not show the transition. 但是当前我检测到单击列表项并将事件发送到Activity,该事件将listview片段从后栈弹出( popBackStackImmediate()
),因此不显示过渡。
Is there a good way to allow back navigation while preserving reverse transition to work as well? 有没有一种好的方法可以允许向后导航,同时又保持反向转换正常工作?
did you try this: 您是否尝试过:
FragmentManager fm = getSupportFragmentManager();
fm.popBackStack();
fm.executePendingTransactions();
PS: use getSupportFragmentManager()
if you're using the support library else use getFragmentManager()
. PS:如果使用支持库,请使用getSupportFragmentManager()
,否则请使用getFragmentManager()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.