我发现在 NestedScorllView 里面的 RecyclerView 总是会触发加载更多,我直接在你的 sample 上加了点代码,百分百重现这个问题,在寻找原因中。
public class NestedActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nested);
final RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
final Issue9Adapter adapter = new Issue9Adapter(10);
rv.setAdapter(adapter);
LoadMoreWrapper.with(adapter)
.setLoadMoreEnabled(true)
.setListener(new LoadMoreAdapter.OnLoadMoreListener() {
@Override public void onLoadMore(LoadMoreAdapter.Enabled enabled) {
rv.postDelayed(new Runnable() {
@Override public void run() {
adapter.addItem();
}
}, 2000);
}
}).into(rv);
}
private class Issue9Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private int mCount;
public Issue9Adapter(int count) {
mCount = count;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false);
return new IssueHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((IssueHolder) holder).mTextView.setText(position + "");
}
@Override
public int getItemCount() {
return mCount;
}
public void clear() {
final int count = mCount;
mCount = 0;
notifyItemRangeRemoved(0, count);
mCount = 15;
notifyItemRangeInserted(0, mCount);
}
public void addItem() {
final int positionStart = mCount;
mCount+= 5;
notifyItemRangeInserted(positionStart, 5);
}
class IssueHolder extends RecyclerView.ViewHolder {
TextView mTextView;
public IssueHolder(View itemView) {
super(itemView);
mTextView = (TextView) itemView.findViewById(R.id.text);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.github.nukc.sample.NestedActivity"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false"
>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>