View details_container = findViewById(R.id.details_container);
View list_container = findViewById(R.id.list_container);
// You can select the direction left/right/up/down and the duration
CustomAnimator.slide(list_container, details_container,CustomAnimator.DIRECTION_LEFT, 400);
override fun getTheme() = R.style.AppFullScreenDialogTransparentTitleBar
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog?.window?.setWindowAnimations(R.style.WindowSlideInAndOutAnimation)
//rest of code on view created here
}
7条答案
按热度按时间p3rjfoxz1#
通过@Sandra更新For Android v19+ see this link
您可以创建自己的动画。将动画XML文件放置在
res > anim
中enter_from_left.xml
enter_from_right.xml
exit_to_left.xml
exit_to_right.xml
你可以改变持续时间到短动画时间
或长动画时间
用法(注意,对事务调用方法的顺序很重要。在调用.replace、.commit之前添加动画):
carvr3hs2#
有三种方法可以在片段中实现事务动画。
转换
因此需要使用其中一个内置的Transitions,使用setTranstion()方法:
自定义动画
也可以使用setCustomAnimations()方法自定义动画:
向上滑动.xml
向下滑动.xml
多个动画
最后,还可以在一个事务中启动多个片段动画,这样可以实现一个片段向上滑动,而另一个片段同时向下滑动的非常酷的效果:
To more detail you can visit URL
**注:-**您可以根据您的要求检查动画,因为上面可能有问题。
1tuwyuhd3#
slide_in_down.xml
slide_in_up.xml
slide_out_down.xml
slide_out_up.xml
方向=向下
方向=向上
vuktfyat4#
我遇到了同样的问题,我使用了简单的解决方案
1)在动画文件夹中创建sliding_out_right. xml
2)在动画文件夹中创建sliding_in_left. xml
3)简单地使用片段事务setCustomeAnimations()和两个自定义xml以及两个默认xml进行动画,如下所示:
olqngx595#
这是我使用的另一个解决方案:
类的用法。假设你有两个片段(list和details片段),如下所示
用法
当用户按下返回键时,可以使用函数
CustomAnimator.reversePrevious();
获取上一个视图。1bqhqjot6#
在从一个片段过渡到另一个片段的过程中也有同样的白色问题。在navigation.xml中设置导航和动画。
所有片段中的背景相同,但白色空白屏幕。因此,我在执行过渡期间设置片段中的navOptions
这对我很有效。转换之间没有白色。神奇)
bfhwhh0e7#
对我来说,唯一能够去除动画上白色背景的方法是,我更改为DialogFragment而不是Fragment,并添加以下代码:
创建了以下样式:
然后在对话框片段中引用这些样式,如下所示:
然后我就像平常一样通过导航组件导航到片段(还要注意将导航XML文件中片段的类型更改为对话框)