gpt4 book ai didi

java - 如何在动画后隐藏textview

转载 作者:行者123 更新时间:2023-12-01 17:45:46 25 4
gpt4 key购买 nike

我想单击Button它将显示TextView可见(执行幻灯片向下动画),然后想再次单击该按钮它将执行另一个动画(向上幻灯片)。之后不需要显示 TextView
我如何解决它?
请任何人有答案来帮助我。

bclickss.setOnClickListener(new View.OnClickListener() {
boolean visible;
@Override
public void onClick(View v) {
if( visible = !visible) {
tv2.setVisibility(visible ? View.VISIBLE : View.GONE);
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
tv2.startAnimation(anim);
}
else {
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
tv2.startAnimation(anim);
tv2.setVisibility(View.GONE);
}
}
});

最佳答案

startAnimation之前使用它

if (tv2.animation != null) tv2.animation.setAnimationListener(null)//needed not in all cases
tv2.clearAnimation()

anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
tv2.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
tv2.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
tv2.startAnimation(anim);

在第二个动画中,你需要这样的东西:

if (tv2.animation != null) tv2.animation.setAnimationListener(null)//needed not in all cases
tv2.clearAnimation()

anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
tv2.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
tv2.startAnimation(anim);

关于java - 如何在动画后隐藏textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55533104/

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