我一直在浏览关于在Android 2.2中处理AnimationListeners时出现闪烁的尽可能多的主题,但我无法完全解决我的问题。
我有一个LinearLayout 'popover',用户触摸它可以向下移动约100像素,并再次触摸以将其移回。我终于让它在第一部分工作正常(感谢建议,在正在动画的视图上调用clearAnimation()),但在相反的情况下(即将视图移回),开始时会出现闪烁。我不能在onAnimationStart()方法中调用clearAnimation(),因为它不会执行动画!
当然,如果我使用setFillAfter()而没有任何动画监听器,所有动画都能完美地工作,但是触摸区域不会移动(因为视图本身没有“实际”移动)。
非常感谢任何帮助。
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);
}
});