动画在高密度设备上不平滑



我在更高密度的android设备上遇到了Fragment setCustomAnimations问题。

我正在做翻转卡片动画。在mdpi和hpid设备上,动画非常流畅。然而,在xhdpi、xxhdi和xxxhdpi设备上,动画可以工作,但看起来跳过了几帧。

我使用这段代码进行片段转换。

这是动画中的

<!-- Before rotating, immediately set the alpha to 0. -->
<objectAnimator
    android:duration="0"
    android:propertyName="alpha"
    android:valueFrom="1.0"
    android:valueTo="0.0" />
<!-- Rotate. -->
<objectAnimator
    android:duration="500"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:propertyName="rotationY"
    android:valueFrom="180"
    android:valueTo="0" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
<objectAnimator
    android:duration="1"
    android:propertyName="alpha"
    android:startOffset="250"
    android:valueFrom="0.0"
    android:valueTo="1.0" />
<!-- Rescale in -->
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="250"
    android:propertyName="scaleX"
    android:startOffset="250"
    android:valueFrom="0.60"
    android:valueTo="1.0" />
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="250"
    android:propertyName="scaleY"
    android:startOffset="250"
    android:valueFrom="0.60"
    android:valueTo="1.0" />

这是输出动画

<!-- Rotate. -->
<objectAnimator
    android:duration="500"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:propertyName="rotationY"
    android:valueFrom="0"
    android:valueTo="-180" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
<objectAnimator
    android:duration="1"
    android:propertyName="alpha"
    android:startOffset="250"
    android:valueFrom="1.0"
    android:valueTo="0.0" />
<!-- Rescale out -->
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="250"
    android:propertyName="scaleX"
    android:valueFrom="1.0"
    android:valueTo="0.60" />
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="250"
    android:propertyName="scaleY"
    android:valueFrom="1.0"
    android:valueTo="0.60" />

即使我去掉了缩放动画,它在mdpi和hdpi设备上看起来仍然更平滑。

就在今天,我发布了两个关于类似问题的冗长答案。我把你介绍给。。。滚动ListView时图像正在更改。

看来你其他的一切都在运转。请随时联系我们,尤其是在不久的将来我可能会遇到这个问题。对我来说,我必须监视这两个帖子,呵呵。

我发现这部动画为我跳过了几帧,但这大大改进了它:

        @Override
        public void onViewCreated (View view, Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);
            view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }

还要考虑的是,如果你的动画在高分辨率设备上变得不那么平滑,那可能是你的图像缩放得太大,占用大量内存并降低速度-当我把一个大的高分辨率图像放在"drawable"文件夹中时,我自己也经历过这种情况,我认为不会应用缩放(这个文件夹通常只用于用xml指定的资源),但事实上,它被视为mdpi图像,因此在高分辨率设备上不必要的放大可能会扼杀动画的性能

最新更新