关于可见性变化的动画视图(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! ;)
更多推荐
发布评论