java - 如何使用 ViewPropertyAnimation 制作从右到左的平移动画?
问题描述
我试图显示一个从右到左动画的片段,就好像它来自屏幕的右侧,但我的代码完全相反。
flBackground.animate().setDuration(250).x(0).translationX(0).alpha(1).start();
flBackground 这里是我的片段中根视图的 id。
我玩的是“translationX”方法。我以像素为单位给出了屏幕宽度,但我的片段离开了屏幕。ViewPropertyAnimation 中是否有一种方法可以设置视图的初始定位以从中进行动画处理?
我只想使用 ViewPropertyAnimation,而不是其他 Animation 对象。其他的都很大,我想为我的项目编写简单的代码。
解决方案
您可以使用FragmentTransaction.setCustomAnimations()
. 这是最好的方法。
例子:
getFragmentManager().beginTransaction()
.setCustomAnimations(R.animator.slide_right, R.animator.slide_left)
.add(R.id.list_fragment_container, YourFragment.instance())
.commit()
推荐阅读
- javascript - Javascript绑定函数实现
- android - 使用 MDC 在 android 中创建材质微调器下拉列表
- javascript - 使用 React.JS 将图像文件与其他数据一起发送到 Java 后端
- r - 以特定格式打印 R 字符串
- virtocommerce - 如何解决 Virto Commerce 主题丢失错误?
- javascript - 为什么 redux-loop 操作会跳过所有中间件?
- python - 如何通过数据框中的列循环函数并添加到新列
- z3 - z3不解量词表达式,表达式为sat
- html - 停止移动菜单后面的文本滚动
- java - 为什么控制器显示问题而不是西里尔字符?