gpt4 book ai didi

java - Android ImageView 动画很慢

转载 作者:行者123 更新时间:2023-11-30 08:41:05 31 4
gpt4 key购买 nike

我正在尝试同时为多个 ImageView 应用多重动画。下面是代码 fragment 。

    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();

这会在滑动时应用于每个项目。

当我在屏幕上滑动时,图像将会动画化。当图像数量增加时,此动画非常慢。我试过在下面提供

1.添加Layer类型并在动画结束时设置为null

2.尝试在Manifest中设置hardwareaccelerated属性

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

4.添加了元素的动画缓存。

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

是否有任何选项可以提高动画性能或 android 中的任何替代方案?

提前致谢。

最佳答案

使用ViewPropertyAnimator .它可能是为 View 设置动画的最简单方法,而且通常非常流畅。对于您的示例,它将是这样的:

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

检查 documentation对于所有可用的方法。

编辑:如果多个动画同时滞后,请尝试使用 Handler它将为您处理线程,并且应该使它更顺畅。像这样:

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());

}
});
}

关于java - Android ImageView 动画很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35306742/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com