【发布时间】:2012-03-12 08:42:14
【问题描述】:
我一直在搜索关于这个主题的尽可能多的线程,我可以在 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);
}
});
【问题讨论】: