作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我使用了一些我为滑动面板找到的代码,基本上它可以工作,但有一个小问题。
动画在面板第一次打开时不起作用。
这是动画的代码:
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);
为什么我第一次打开面板时没有动画,但所有其他面板都有?
最佳答案
你什么时候打电话?它可能只是在“第一次之后”这样做,因为当您第一次调用它时面板还没有被渲染,并且 getHeight()
返回 0。尝试等到 getHeight()
有一个值然后开始动画。您也可以尝试将值硬编码为某种东西,以测试我的理论是否正确。
关于android - TranslateAnimation - 动画仅在第二次后起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8215320/
我是一名优秀的程序员,十分优秀!