我是 Android 编程新手,最近我在寻找对象的简单淡出动画。我已将其放入我的代码中并进行了测试,结果很不稳定。我检查了日志并看到了这个:
11-05 19:19:21.319:我/Choreographer(12759):跳过了 40 帧!应用程序可能在其主线程上做了太多工作。
这是我在 MainActivity 类中的代码
private MainActivity actMain;
FadeIn fadeClass = new FadeIn();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.view_switcher);
actMain = this;
new Thread() {
@Override
public void run() {
// If there are stories, add them to the table
try {
// code runs in a thread
runOnUiThread(new Runnable() {
@Override
public void run() {
fadeClass.animation(actMain);
}
});
} catch (final Exception ex) {
Log.i("---", "Exception in thread");
}
}
}.start();
}
来自 FadeIn 类:
private View view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void animation(Activity context) {
final View view = context.findViewById(R.id.fadeOutLayer);
Animation fadeOut = new AlphaAnimation(1f, 0f);
fadeOut.setDuration(3000);
fadeOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.GONE);
}
});
view.startAnimation(fadeOut);
}
谢谢!
最佳答案
您正在主线程中创建并执行一个新线程,在这个新线程内部,您正在执行一个 runOnUiThread,它与主线程同步并执行其中的内容。这是没有意义的,因为就像在onCreate中执行runOnUiThread的内容。
我建议您使用“fadeClass.animation(actMain);”直接在 onActivityCreated 内部
关于java - I/Choreographer(12759) : Skipped 40 frames! 应用程序可能在其主线程上做了太多工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26763408/