How to use a sliding transition with Compatibility Library v4 Fragment Transactions

柔情痞子 提交于 2019-12-11 09:22:16

问题


All I want is to be able to use FragmentTransaction.replace(...) and have fragments slide into and out of place just like activities, using the default activity animation.

By default the fragments simply appear and disappear. That is an acceptable default behavior.

With FragmentTransaction.setTransition(...) I can get Fragments to fade with a slight zooming animation. That is pretty cool, but it looks nothing like what activities do.

With FragmentTransaction.setCustomAnimation(...) a clusterfuck of things happen, and it looks ugly as hell.

And now I'm out of options. All I want to do is to have fragments slide left as I push to the stack, and have fragments slide right as I pop from the stack. Anybody know how to do this short of implementing my own FragmentManager?


回答1:


I have somewhat gotten around the problem by placing all of my fragments into a ViewPager. I can then setCurrentItem() to scroll between fragments. It's not pretty, and it takes a fair bit of manual effort, but it runs nice and quickly.

If there are any answers that aren't as hackish as what I've done, I'll definitely accept them.



来源:https://stackoverflow.com/questions/7296475/how-to-use-a-sliding-transition-with-compatibility-library-v4-fragment-transacti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!