0
我想用戶刷卡刷新,所以我需要確保我在recycleview。這頂是我的代碼:機器人 - 如何檢查回收視圖是否是在頂部或不
LinearLayoutManager mLayoutManager;
recycle = (RecyclerView) findViewById(R.id.recycle);
mLayoutManager = new LinearLayoutManager(this);
recycle.setLayoutManager(mLayoutManager);
recycle.addOnScrollListener(new RecyclerView.OnScrollListener() {
boolean enable = false;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(recycle != null && mLayoutManager.getChildCount() > 0){
boolean firstItemVisible = mLayoutManager.findFirstVisibleItemPosition() == 0;
boolean topOfFirstItemVisible = mLayoutManager.getChildAt(0).getTop() == 0;
Log.v("this",firstItemVisible + " "+topOfFirstItemVisible);
//boolean topOfFirstItemVisible = recycle.getChildAt(0).getTop() == 0;
enable = firstItemVisible && topOfFirstItemVisible;
}
mSwipeRefreshLayout.setEnabled(enable);
}
});
}
,你可以看到,我使用的是一個布爾值,我想檢查是否recycleView是在頂部,那麼它使swifeLayout。
我該怎麼做?此代碼不工作,當我在recycleView的頂部時,它不啓用swipeLayout。
檢查這個http://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview –