【问题标题】:Weird problem with button clicking in a layout that has a RecyclerView在具有 RecyclerView 的布局中单击按钮的奇怪问题
【发布时间】:2021-03-06 14:42:59
【问题描述】:

我遇到了一个非常奇怪的问题。我有一个带有 RecyclerView 的布局和一个打开动画的按钮。关键是如果我在应用程序执行后立即单击按钮 - 比如说 10 秒,一切都很好。但是,如果我让应用程序闲置几秒钟,而没有触摸任何东西,那么当我再次单击按钮时,动画根本就不会开始。然而,如果在那之后我用手指(在任何地方!)在屏幕上滑动 RecyclerView,那么动画会突然触发。好像它只是在我与 RecyclerView 交互后才以某种方式冻结并“醒来”。好像几秒钟后 RecyclerView 以某种方式使其与动画相关的对象进入睡眠状态,并且它们仅在 RecyclerView 滑动后“唤醒”?..显然听众“上床睡觉”......有没有办法保持动画- 相关对象始终“清醒”?

这里是动画功能:

private void recyclerViewAnimate(final RecyclerView recyclerView, LayoutAnimationController controller) {
        if(isAnimating){
            return;
        }
        controller = AnimationUtils.loadLayoutAnimation(recyclerView.getContext(), R.anim.layout_recycleview_disappear);
        recyclerView.setLayoutAnimation(controller);

        recyclerView.setLayoutAnimationListener(new Animation.AnimationListener() {
                                       public void onAnimationStart(Animation animation) {
                                           isAnimating = true;
                                           bt_add.animate().rotationXBy(180).setDuration(400).start();
                                           addButtonLayout.animate().setDuration(400).alpha(0).withEndAction(new Runnable() {
                                               @Override
                                               public void run() {
                                                   addButtonLayout.setVisibility(View.INVISIBLE);
                                               }
                                           });
                                       }
                                       public void onAnimationRepeat(Animation animation) {}
                                       public void onAnimationEnd(Animation animation) {
                                           recyclerView.setVisibility(View.GONE);
                                           layoutSettings.setVisibility(View.VISIBLE);
                                           layoutSettings.animate().scaleX(0.95f).setDuration(0).withEndAction(new Runnable() {
                                               @Override
                                               public void run() {
                                                   layoutSettings.animate().alpha(1)
                                                           .scaleY(1.01f).scaleX(1f).setDuration(400).withEndAction(new Runnable() {
                                                       @Override
                                                       public void run() {
                                                           settingsText.animate().setDuration(300).alpha(1).start();
                                                           isAnimating = false;
                                                          recyclerView.setLayoutAnimationListener(null);
                                                       }
                                                   }).start();
                                               }
                                           }).start();
                                       }
                                   });
        recyclerView.scheduleLayoutAnimation();
    }

【问题讨论】:

  • 请发帖layout_recycleview_disappear.xml 我可以帮忙
  • 您将动画设置为整个recyclerview,这意味着动画在适配器更改或视图在滚动时被回收时运行。如果您想在特定项目视图中为特定按钮设置动画,则必须将这些动画设置为按钮本身。
  • 伙计们,我解决了这个问题!而不是设置 scheduleLayoutAnimation();我需要使用 startLayoutAnimation();显然 schedulrLayoutAnimation() 函数实际上只在您以某种方式与 RecyclerView 交互时才起作用,而 startLayoutAnimation() 会根据请求立即执行它。

标签: android android-recyclerview android-animation


【解决方案1】:

我需要使用startLayoutAnimation();而不是设置scheduleLayoutAnimation();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 2014-06-12
    • 1970-01-01
    • 2016-06-11
    • 2014-08-17
    • 2012-08-03
    相关资源
    最近更新 更多