通过动画交换 Activity 中的片段
我想通过动画交换活动中的两个片段。假设 PageA 用于片段 A 和屏幕左侧,PageB 用于片段 B,即屏幕右侧。现在我希望当我单击 pageA 上的按钮时,PageA 将移动到屏幕的右侧并带有一些过渡动画。
我尝试使用下面的代码来替换位置
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new FragB());
fragmentTransaction.commit();
寻找一些线索。
I want to swap two fragment in an activity via animation.Suppose PageA is for fragement A and left side on the screen and PageB is for fragment B i.e. on the right side of the screen. Now i want that when i click a button on pageA then PageA will move to the right side of the screen with some transition animation.
I tried the below code to replace the position
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new FragB());
fragmentTransaction.commit();
Looking for some clue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老问题,您可能已经弄清楚了,但供将来参考:
这是当您通过代码替换片段时用来设置自定义动画的内容:
这是slide_in_left动画的示例:
请注意,如果您是,则这是动画使用兼容性库。相反,如果您使用的是原生支持 FragmentManager 的 SDK,那么您的动画将如下所示:
这是因为兼容性库不支持新的 objectAnimator 类型,而仅实现旧的动画框架。
Old questiion and you probably already figured it out, but for future reference:
here's what you use to set a custom animation when you replace a fragment via code:
Here is an example of the slide_in_left animation:
Note that this is the animation if you are using the compatibility library. Instead if you are using and SDK with native support for the FragmentManager then your animation will look like this:
This is because the compatibility library does not support the new objectAnimator type and instead only implement the old animation framework.