如何使用兼容库V4片段交易滑动过渡 [英] How to use a sliding transition with Compatibility Library v4 Fragment Transactions

查看:148
本文介绍了如何使用兼容库V4片段交易滑动过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的是能够使用FragmentTransaction.replace(...),并有碎片滑入进出的地方,就像活动,使用默认的活动动画。

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.

使用FragmentTransaction.setTransition(...)我可以得到片段有轻微的缩放动画褪色。那是pretty很酷,但它看上去一点也不像什么活动做的。

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.

使用FragmentTransaction.setCustomAnimation(...)的事情发生clusterfuck,它看起来丑陋的地狱。

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

现在我跳出选项。所有我想要做的是有碎片滑块向左我推到堆栈中,并有片段向右滑动,因为我从栈中弹出。任何人都知道如何做到这一点短期实现我自己的FragmentManager的?

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?

推荐答案

我有所通过把我所有的碎片进入ViewPager解决该问题得到。然后我可以setCurrentItem(),以片段之间滚动。这不是pretty,它需要手动工作公平位,但它运行好和快。

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.

如果有一些不如自己的所作所为为hackish的任何答案,我一定会接受。

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

这篇关于如何使用兼容库V4片段交易滑动过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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