android - 翻译动画看起来真的很慢/生涩/滞后

标签 android animation lag translate-animation

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

<?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"/>

现在它工作正常,除了它在动画时似乎闪烁/ SCSS ?这是标准吗?

我确实有 6 个不同的 View 同时被激活,这是原因吗?

这是我设置动画的方式:

// 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]);
}

现在我是不是漏掉了什么,因为动画对我来说真的很垃圾......?

最佳答案

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

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

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

关于android - 翻译动画看起来真的很慢/生涩/滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7128835/

相关文章:

android - 拉动刷新不适用于 firebaseRecyclerAdapter

animation - 在 CSS3 3D 转换方面需要帮助

animation - Flutter 代码创建滞后动画。这里有什么问题吗?

Javascript:为什么我的 Raphaeljs 动画滞后?甚至不一致

r - 我如何滞后一个 data.frame?

android - map View 安卓 :clickable ="false" not working?

android - SmsManager 不断重试在 HTC Desire 上发送短信

java - 错误显示我的 sqlite 数据库表中不存在特定列

ios - 像视频一样显示一系列图像?

performance - 混合模式滚动延迟问题