我使用了一些找到的代码来制作一个滑动面板,基本上它可以工作,但有一个小问题。
第一次打开面板时,动画不起作用。
以下是动画的代码:
TranslateAnimation anim = null;
m_isOpen = !m_isOpen;
if (m_isOpen) {
setVisibility(View.VISIBLE);
anim = new TranslateAnimation(0.0f, 0.0f, getHeight(), 0.0f);
} else {
anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, getHeight());
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
setVisibility(View.GONE);
}
public void onAnimationRepeat(Animation animation) {
// not needed
}
public void onAnimationStart(Animation animation) {
// not needed
}
});
}
anim.setDuration(300);
anim.setInterpolator(new AccelerateInterpolator(1.0f));
startAnimation(anim);
为什么当我打开面板时,第一个面板没有动画,但其他所有面板都有呢?