Closed solomon2 closed 7 years ago
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<app.dinus.com.loadingdrawable.LoadingView
android:id="@+id/loadingView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="100dp"
android:background="@color/white"
app:loading_renderer="CollisionLoadingRenderer" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
RecyclerView监听了OnScrollListener
recycler_view.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int firstVisibleItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
if (newState == 0) {
if (null != recycler_view.getChildAt(0)) {
// if(recycler_view.getChildAt(0).getTop()>=0){
// mCurrentItem=firstVisibleItem;
// }else{
// mCurrentItem=firstVisibleItem+1;
// }
mCurrentItem = firstVisibleItem;
adapter.setCurrentItem(mCurrentItem);
adapter.notifyDataSetChanged();
}
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { }
});
Adapter里面重写了getItemViewType:
public void setCurrentItem(int currentItem) {
this.mCurrentItem = currentItem;
}
@Override
public int getItemViewType(int position) {
if (position == mCurrentItem) {
return TYPE_2;
} else {
return TYPE_1;
}
}
其他没作什么改动
重写了getItemViewType会出问题的。
啊, 那怎么破
我RecyclerView里面需要做分类处理,需要linearLayoutManager.findFirstCompletelyVisibleItemPosition(); 做特殊处理
哦哦 知道了知道了,抱歉,多谢了,我马上试试。
恩 好的
当我设置openLoadMore(size)小于或者等于 listdata.size 的时候就会报错
设置size大于listdata.size就不会触发onLoadMoreRequested