我使用了一些我找到的用於滑動面板的代碼,基本上它可以工作,但有一個小問題。TranslateAnimation - 動畫僅在第二次後才起作用
動畫在面板第一次打開時不起作用。
這裏是動畫的代碼:
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);
爲什麼我第一次打開面板沒有動畫,但所有其他的人存在?
您確定它不起作用嗎?嘗試調試它的一些日誌。當你的面板不可見或者正在創建視圖時,Mabye會啓動嗎? – ania
它不起作用。只有在第一次打開後,動畫才能用於打開和關閉 – piojo
我發現了一種解決方案:不是將面板的可見性設置爲「GONE」,而是在應用程序啓動時關閉面板 – piojo