Android Image View动画缓慢 [英] Android Image view animation is slow

查看:210
本文介绍了Android Image View动画缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试同时对多个图像视图应用多重动画.下面是代码片段.

I am trying to apply multiple-animation for multiple image views at the same time. Below is the code snippet.

    final AnimatorSet animationSet = new AnimatorSet();
            for(int i=0;i<frame.getChildCount();i++){
                final ImageView vw = (ImageView) frame.getChildAt(i);

                animationSet.playTogether(
                        ObjectAnimator.ofFloat(vw, "rotationY", 60),
                        ObjectAnimator.ofFloat(vw, "scaleY", 0.8f),
                        ObjectAnimator.ofFloat(vw, "x", 0)
                );
                animationSet.setDuration(600);
                animationSet.setInterpolator(new DecelerateInterpolator(1.5f));
                animationSet.start();

此项在刷卡时适用于所有项目.

this is applied to every item while swiping.

当我在屏幕上滑动时,图像将进行动画处理.当图像数量增加时,该动画非常慢.我尝试在下面提供

When i swipe on the screen images will animate. This animation is very slow when the image count increases. I have tried providing below

1.添加图层类型并在动画结束时将其设置为空

1.Adding Layer type and setting null while animation ended

2.尝试在清单中设置硬件加速属性

2.Tried Setting hardwareaccelerated aattribute in Manifest

3.尝试在清单中设置大堆属性

3.Tried setting large heap attribute in manifest

4.为项目添加了动画缓存.

4.Added animation cache for items.

5.尝试在高RAM设备上运行.

5.Tried running with high RAM devices.

在Android中是否有任何选项可以改善动画效果或其他替代方案?

is there any option to improve animation performance or any alternatives in android.?

谢谢.

推荐答案

使用 ViewPropertyAnimator . 这可能是对视图进行动画处理的最简单方法,通常很平滑.以您的示例为例:

Use ViewPropertyAnimator . Its probably the easiest way to animate Views and is usually pretty smooth. For your example it would be something like this :

vw.animate()
    .rotationY(60)
    .scaleY(0.8f)
    .setDuration(600)
    .setInterpolator(new DecelerateInterpolator());

查看文档以获取所有可用方法.

Check the documentation for all available methods.

如果同时有多个动画滞后,请尝试使用 Handler 将为您处理Threading,并使其更加流畅. 像这样的东西:

EDIT : If multiple Animations at the same time are lagging, try using a Handler it will take care of the Threading for you, and should make it smoother. Something like this :

private Handler mHandler = new Handler();

for(int i=0;i<frame.getChildCount();i++){
    final ImageView vw = (ImageView) frame.getChildAt(i);

     mHandler.post(new Runnable() {
       @Override
       public void run () {
           vw.animate()
                .rotationY(60)
                .scaleY(0.8f)
                .setDuration(600)
                .setInterpolator(new DecelerateInterpolator());

           }
       });
    }

这篇关于Android Image View动画缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆