RecyclerView
如果设置NestedScrollView
,当我放入recyclerView.setNestedScrollingEnabled(false)
内部时,滚动挂起但问题是如果我设置recyclerView.setNestedScrollingEnabled(false)
然后RecyclerView
适配器{{1}和/ onViewAttachedToWindow(ViewHolder holder)
方法未被调用,滚动列表时也没有调用onViewDetachedFromWindow(ViewHolder holder)
。
我的HeaderView更复杂,因此我无法在onBindViewHolder(ViewHolder holder, int position)
中添加标题,因此我将其放入RecyclerView
当NestedScrollView
位于RecyclerView
NestedScrollView
以下是我的代码;
@Override
public void onViewAttachedToWindow(ViewHolder holder) {
super.onViewAttachedToWindow(holder);
}
@Override
public void onViewDetachedFromWindow(ViewHolder holder) {
super.onViewDetachedFromWindow(holder);
}
活动代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nested_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.NestedScrollView>
适配器代码
RecyclerView recyclerView = findViewById(R.id.recyclerView);
//recyclerView.setNestedScrollingEnabled(false);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
TMPAdapter adapter = new TMPAdapter(this, strings);
recyclerView.setAdapter(adapter);
}