gpt4 book ai didi

Android 动画闪烁

转载 作者:IT老高 更新时间:2023-10-28 23:26:30 28 4
gpt4 key购买 nike

我一直在搜索关于这个主题的尽可能多的线程,我可以在 Android 2.2 中处理 AnimationListeners 时出现的闪烁中找到这些线程,但我无法完全解决我的问题。

我得到的是一个 LinearLayout 'popover',用户触摸它可以向下移动大约 100 个像素,然后再次触摸它可以向上移动。我终于让它在第一部分工作,没有任何闪烁(感谢在动画 View 上调用 clearAnimation() 的建议),但是当做相反的事情(即,将 View 向上移动)时,有一个闪烁开始。我不能真正在 onAnimationStart() 方法中调用 clearAnimation(),因为它不会动画!

当然,如果我在没有任何动画监听器的情况下使用 setFillAfter(),所有动画都可以完美运行,但是 View 的触摸区域不会移动(因为 View 本身并没有“实际”移动)。

任何帮助将不胜感激。

this.popoverTab.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
popoverTab.setClickable(false);
popoverTab.setFocusable(false);
if (popoverHidden) {
Log.d(TAG, "About to show popover");
// the popover is currently hidden, show it.
TranslateAnimation animation = new TranslateAnimation(0, 0, 100, 0);
animation.setDuration(700);
animation.setFillBefore(true);
animation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {

}

public void onAnimationRepeat(Animation animation) {

}

public void onAnimationStart(Animation animation) {
footer.layout(footer.getLeft(), (footer.getTop() - 100), footer.getRight(), footer.getBottom());
}
});
footer.startAnimation(animation);
} else {
Log.d(TAG, "About to hide popover");
// the popover is showing, hide it.
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, 100);
animation.setDuration(700);
animation.setFillAfter(true);
animation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
footer.clearAnimation();
footer.layout(footer.getLeft(), (footer.getTop() + 100), footer.getRight(), footer.getBottom());
}

public void onAnimationRepeat(Animation animation) {

}

public void onAnimationStart(Animation animation) {

}
});
footer.startAnimation(animation);
}
// invert.
popoverHidden = !popoverHidden;
popoverTab.setClickable(true);
popoverTab.setFocusable(true);
}

});

最佳答案

我遇到了同样的问题,几天后我找到了解决方案……谢谢:

http://www.mail-archive.com/android-developers@googlegroups.com/msg67535.html

I figured out a solution to this problem. The clue came from the fact that when showing the view, everything worked fine. Apparently, when the animation is running, the update that would be forced by the show happens in the background and doesn't cause the flicker. Adding a short animation to the back end of the onAnimationEnd() when we are hiding the view makes the flicker go away.

Here is the new onAndimationEnd() in the working code

  public void onAnimationEnd(Animation animation) {
animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
animation.setDuration(1);
mPlayer0Panel.startAnimation(animation);
}

关于Android 动画闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9387711/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com