gpt4 book ai didi

android - TranslateAnimation - 动画仅在第二次后起作用

转载 作者:太空狗 更新时间:2023-10-29 16:23:34 28 4
gpt4 key购买 nike

我使用了一些我为滑动面板找到的代码,基本上它可以工作,但有一个小问题。

动画在面板第一次打开时不起作用。

这是动画的代码:

    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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com