关于可见性变化的动画视图(Animating view on visibility change)

编程入门 行业动态 更新时间:2024-10-23 15:21:48
关于可见性变化的动画视图(Animating view on visibility change)

我正在使用下面给出的代码片段来显示/隐藏RecyclerView中的单击视图。 问题是在第一个显示/隐藏周期后,视图显示片刻然后消失。 这种情况一直持续到我重新开始活动。

public void changeVisibility(final View view, boolean makeVisible) { if (makeVisible) { view.setVisibility(View.VISIBLE); view.setAlpha(0.0f); view.animate().alpha(1.0f); } else { view.animate() .alpha(0.0f) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); view.setVisibility(View.GONE); } }); } }

I'm using the code snippet given below to show/hide a view on click inside a RecyclerView. The issue is that after the first show/hide cycle, the view shows up for a moment then disappears. This keeps happening till I restart the activity.

public void changeVisibility(final View view, boolean makeVisible) { if (makeVisible) { view.setVisibility(View.VISIBLE); view.setAlpha(0.0f); view.animate().alpha(1.0f); } else { view.animate() .alpha(0.0f) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); view.setVisibility(View.GONE); } }); } }

最满意答案

原因是因为你在第一轮显示/隐藏视图后设置onAnimationEnd 。

您应该在不再需要时删除listener 。 添加这个:

view.setListener(null);

到你的if (makeVisible)块应该工作! ;)

Reason because you set onAnimationEnd after the first round of show/hide of the view.

You should remove the listener when you don't need it anymore. Add this:

view.setListener(null);

to your if (makeVisible) block should work! ;)

更多推荐

本文发布于:2023-08-05 05:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   见性   动画   Animating   visibility

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!