繁体   English   中英

如何使用ViewPropertyAnimation制作从右到左的翻译动画?

[英]How to make Right To Left Translation animation with 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()

更多: https : //developer.android.com/reference/android/app/FragmentTransaction#setCustomAnimations(int,%20int,%20int,%20int)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM