小编oro*_*akr的帖子

Android:使用ObjectAnimator将View转换为View维度的小数值

似乎旧的视图动画(translate,scale等等)不再被AnimationInflaterICS 接受了.我在阅读4.0.4的代码,并明确预计只有XML元素set,objectAnimator,animator.

即使http://developer.android.com/guide/topics/resources/animation-resource.html上的文档继续包含视图动画,它们似乎也已弃用.例如,尝试使用它们会导致错误java.lang.RuntimeException: Unknown animator name: translate.

因此,有必要使用Android ObjectAnimator.但是,它不接受自身或其父级(translationX例如,宽度)的关联维度的小数值,就像旧视图动画在表单中所做的那样"75%p".

ObjectAnimator通过以编程方式获取片段的大小来在运行时手动构建是不可行的,因为它FragmentTransaction仅接受由渣油指定的声明性动画.

我的目标是在屏幕外翻译一个填满整个Activity的Fragment(我基本上是在两个片段之间进行转换).这是现有的TranslationAnimation实现(由于某些原因slide_in_right.xml,它与其对应物slide_out_left.xml没有公开android.R.anim,因此我必须在我的代码库中复制它们):

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:fromXDelta="100%p"
    android:toXDelta="0"
    android:duration="@android:integer/config_mediumAnimTime"/>
</set>
Run Code Online (Sandbox Code Playgroud)

我的API级别设置为14.

谢谢!

animation android

40
推荐指数
3
解决办法
7万
查看次数

标签 统计

android ×1

animation ×1