0

我有RecyclerView上面,我有一个AppBarLayout的高度大于255像素。当用户滚动RecyclerView时,AppBarLayout有一个问题。为了避免这种情况,我决定手动扩展AppBarLayout。我用的3。我用下面的代码来听RecyclerView跨度由GridLayoutManager的RecyclerView顶部达到检测具有多个列的RecyclerView的顶部?

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 
     @Override 
     public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 
      super.onScrollStateChanged(recyclerView, newState); 
      if (newState == RecyclerView.SCROLL_STATE_IDLE) { 
       int firstVisiblePosition = ((LinearLayoutManager)recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition(); 
       if (firstVisiblePosition == 0) { 
        appBarLayout.setExpanded(true, true); 
       } 
      } 
     } 
    }); 

但问题是,现在我不能向上滚动recyclerview

回答

0

一个可能的解决方案是滚动的应用程序酒吧与动画。

if (mIsAppBarExpanded) { 
     CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams(); 
     final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); 
     if (behavior != null) { 
      ValueAnimator valueAnimator = ValueAnimator.ofInt(); 
      valueAnimator.setInterpolator(new DecelerateInterpolator()); 
      valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
       @Override 
       public void onAnimationUpdate(ValueAnimator animation) { 
        behavior.setTopAndBottomOffset((Integer) animation.getAnimatedValue()); 
        mAppBarLayout.requestLayout(); 
       } 
      }); 
      valueAnimator.setIntValues(0, -mAppBarLayout.getTotalScrollRange()); 
      valueAnimator.setDuration(400); 
      valueAnimator.start(); 
     } 
    } 

来检查应用程序栏已经崩溃或不

mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 
     @Override 
     public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
      mIsAppBarExpanded = Math.abs(verticalOffset) != appBarLayout.getTotalScrollRange(); 
     } 
    }); 
相关问题