翻译动画看起来真的很jenky/jerky/laggy
大家好,我正在使用翻译动画,如下所示:
<?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]);
}
现在我在这里遗漏了一些东西,因为动画对我来说实际上看起来像垃圾......?
Hey guys I'm using a translate animation as seen here:
<?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"/>
Now it works fine, except that it seems to flicker/jerk while animating? Is this standard?
I do have 6 different views being animated at same time, is this cause?
This is how I set the animations:
// 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]);
}
Now am I missing something here, cause the animation actually looks like crap to me..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果多个动画是一个问题,那么由于您将所有子
View
放入一个更大的封闭View
中,因此在整个mBackgroundView
上运行动画> 如果它没有其他孩子,则应该是静止的。否则,向mBackgroundView
添加一个中间View
,其中包含所有需要动画的内容。然后您可以将动画应用到中间View
。编辑:我注意到您正在使用
AnimationUtils
制作 6 个相同的动画。根据我的理解,您可以对所有视图仅使用一个。编辑 2:尝试在执行
addView
之后而不是之前启动动画。If multiple animations is a problem, then since you are putting all the child
View
s into a larger enclosingView
, run the animation on the entiremBackgroundView
if it has no other children that should be stationary. Otherwise, add an intermediateView
tomBackgroundView
containing all the ones that need animation. Then you can just apply the animation to the intermediateView
.Edit: I noticed you are making 6 identical animations with
AnimationUtils
. From my understanding you can just use a single one for all views.Edit 2: Try starting the animation after you do
addView
, instead of before.