翻译动画看起来真的很jenky/jerky/laggy

发布于 2024-11-30 21:57:04 字数 1854 浏览 1 评论 0原文

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

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱人如己 2024-12-07 21:57:04

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

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

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

If multiple animations is a problem, then since you are putting all the child Views into a larger enclosing View, run the animation on the entire mBackgroundView if it has no other children that should be stationary. Otherwise, add an intermediate View to mBackgroundView containing all the ones that need animation. Then you can just apply the animation to the intermediate View.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文