1

안에 내가 NestedScrollView 내부 RecyclerView을 포함 RecyclerView의 스크롤이 거짓로 설정되어 있기 때문에nestedScrollView

mRecyclerView.setNestedScrollingEnabled(false);

설정입니다 RecyclerView에 페이지 매김을 구현하는 방법, 나는의 스크롤 위치를받지 않습니다 이 때문에 RecyclerViewRecyclerView에 페이지 매김을 할 수 없습니다.

은 또한이

mRecylerview.addOnScrollListener(new RecyclerView.OnScrollListener() { 

     @Override 
     public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 
      super.onScrollStateChanged(recyclerView, newState); 
     } 


     @Override 
     public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 

      if(dy > 0) { 
       totalItemCount = linearLayoutManager.getItemCount(); 
       lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition(); 
       if (!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { 
        // End has been reached 
        // Do something 
        if (mOnLoadMoreListener != null) { 
         mOnLoadMoreListener.onLoadMore(); 
         isLoading = true; 
        } 

       } 
      } 
     } 
    }); 

그러나 여기 lastVisibleItem 항상리스트의 길이를 표시 할 수 있습니다 노력했다.

몇 파고 후, 나는 우리가 NestedScrollView 내부 RecylerView를 사용할 때 그 lastVisibleItem 항상 목록의 크기를 제공하는 이유는 그래서 모든 뷰가 처음으로 작성되는 것을 발견했다.

내가 잘못하면 설명해주십시오. 어떻게 이 작동합니까?

내 페이지 작업을 할 수 있도록 RecyclerView 스크롤 위치를 얻을 수있는 해결 방법이 있습니까?

도움이 될 것입니다.

+1

NestedScrollView입니까? –

답변

3

가 여기에 스크롤 미리 감사는 해결책을 찾았

scroll.getViewTreeObserver().addOnScrollChangedListener(() -> { 
       View view = (View) scroll.getChildAt(scroll.getChildCount() - 1); 

       Log.d("CategoryNeswList", scroll.getChildCount() + " child"); 
       int diff = (view.getBottom() - (scroll.getHeight() + scroll 
         .getScrollY())); 

       if (diff == 0) { 
//      getPlaylistFromServer("more"); 
        Toast.makeText(mContext, "Load More", Toast.LENGTH_SHORT).show(); 
       } 
      });