如何通过兼容性库 v4 片段事务使用滑动过渡
我想要的只是能够使用 FragmentTransaction.replace(...) 并使片段像活动一样滑入和滑出位置,使用默认的活动动画。
默认情况下,片段只是出现然后消失。这是可接受的默认行为。
使用 FragmentTransaction.setTransition(...) 我可以让片段以轻微的缩放动画淡出。这很酷,但它看起来与活动的作用完全不同。
使用 FragmentTransaction.setCustomAnimation(...) 会发生一堆乱七八糟的事情,而且看起来很难看。
现在我别无选择。我想做的就是当我推入堆栈时让片段向左滑动,当我从堆栈中弹出时让片段向右滑动。有人知道如何实现我自己的 FragmentManager 吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将所有片段放入 ViewPager 中,我在某种程度上解决了这个问题。然后我可以 setCurrentItem() 在片段之间滚动。它并不漂亮,并且需要相当多的手动操作,但它运行良好且快速。
如果有任何答案不像我所做的那样黑客,我一定会接受它们。
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.