【问题标题】:Translate Animation seems really jenky/jerky/laggy翻译动画看起来真的很jeky/jerky/laggy
【发布时间】:2011-10-31 00:37:46
【问题描述】:

大家好,我正在使用翻译动画,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
     android:fromXDelta="0" 
     android:toXDelta="0%" 
     android:fromYDelta="-150"
     android:toYDelta="125%p" 
     android:duration="4500"/>

现在它可以正常工作了,只是在制作动画时它似乎闪烁/抖动?这是标准吗?

我确实有 6 个不同的视图同时被动画化,这是原因吗?

这是我设置动画的方式:

// Create animation for  image
for(x = 0; x < 6; x++){
this.movement[x] = AnimationUtils.loadAnimation(this, R.layout.animation_test);
this.movement[x].reset();
this.movement[x].setRepeatCount(Animation.INFINITE);
this.movement[x].setRepeatMode(Animation.RESTART);
this.movement[x].setStartOffset(x * 1250);
this.movement[x].setAnimationListener(this);    
}

// Create Droplet Layout
for(x = 0; x < 6; x++){
this.mDropletLayout[x] = new LinearLayout(this);
// Randomize        
final long rnd = Math.round(Math.random() * 480);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(                                                       RelativeLayout.LayoutParams.WRAP_CONTENT,                                               RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = (int) rnd;
this.mLayout[x].setLayoutParams(params);        
}

this.mLayout[0].setBackgroundResource(R.drawable._1);
this.mLayout[1].setBackgroundResource(R.drawable._2);
this.mLayout[2].setBackgroundResource(R.drawable._3);
this.mLayout[3].setBackgroundResource(R.drawable._4);
this.mLayout[4].setBackgroundResource(R.drawable._5);
this.mLayout[5].setBackgroundResource(R.drawable._6);

// Attach
for(x = 0; x < 6; x++){
// Attach Animation
this.mLayout[x].startAnimation(this.movement[x]);
// Attach
this.mBackgroundView.addView(this.mLayout[x]);
}

现在我在这里遗漏了什么,因为动画对我来说实际上看起来像垃圾......?

【问题讨论】:

    标签: android animation lag translate-animation


    【解决方案1】:

    如果多个动画是一个问题,那么由于您将所有子 Views 放入更大的封闭 View,如果它没有其他应该静止的子动画,则在整个 mBackgroundView 上运行动画。否则,添加一个中间 ViewmBackgroundView 包含所有需要动画的。然后你可以将动画应用到中间的View

    编辑:我注意到您正在使用 AnimationUtils 制作 6 个相同的动画。据我了解,您可以对所有视图只使用一个。

    编辑 2:尝试在执行 addView 之后而不是之前启动动画。

    【讨论】:

    • 拥有不同动画的重点是所有视图都应该在任何给定时间处于动画的不同阶段?如果我只使用一个,那么它们都会一起移动?不过感谢您的快速回复,并指出我什至在将动画添加到视图之前就开始了动画。
    • 哦,那我猜你将不得不做你现在正在做的个别动画,但只需使用一个 Animation 对象。
    猜你喜欢
    • 2015-11-09
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 2019-09-03
    相关资源
    最近更新 更多