NestedScrollView中的多个Recyclerview不会进行java视图回收
我在管理Recyclerview
内的多个NestedScrollView
回收时遇到了一个问题。让我告诉你我想做什么-
- 我有两种框架布局,即框架1和框架2李>
- 我有两个包含recyclerview的片段,第一个片段的recyclerview水平显示项目,而第二个片段的recyclerview垂直显示列表李>
- 现在我把这两个
FrameLayout
都放在了一个NestedScroolView
中,frame1 recyclerview正确地回收了所有视图,但是frame2 recylerview没有回收视图,不知道为什么?它首先加载所有项目,然后显示在屏幕上李>
一些代码:
主要活动。java
FragmentTransaction transaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FragmentA frag1=new FragmentA();
FragmentB frag2=new FragmentB();
transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame1, frag1);
transaction.addToBackStack(frag1.getClass().getName());
transaction.commit();
transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame2, frag2);
transaction.addToBackStack(frag2.getClass().getName());
transaction.commit();
}
main。xml
<LinearLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content">
<安卓.support.v4.widget.NestedScrollView
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="vertical">
<FrameLayout
安卓:id="@+id/frame1"
安卓:layout_width="match_parent"
安卓:layout_height="185dp" />
<FrameLayout
安卓:id="@+id/frame2"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
/>
</LinearLayout>
</安卓.support.v4.widget.NestedScrollView>
</LinearLayout>
片段a:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.recycler_view, container, false);
mDataListView = (RecyclerView) v.findViewById(R.id.data_list_view);
mDataListView .setHasFixedSize(true);
final GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), getActivity().getResources().getInteger(R.integer.playlist_categories_columns), GridLayoutManager.VERTICAL, false);
mDataListView .setNestedScrollingEnabled(false);
}
}));
return v;
}
片段b:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.recycler_view, container, false);
mDataListView = (RecyclerView) v.findViewById(R.id.data_list_view);
mDataListView .setHasFixedSize(true);
final GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 1, GridLayoutManager.HORIZONTAL, false);
mDataListView .setLayoutManager(gridLayoutManager);
mDataListView .setNestedScrollingEnabled(false);
}
}));
return v;
}
回收者视图。xml
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.v7.widget.RecyclerView xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:id="@+id/data_list_view"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
我希望我的问题清楚
共 (0) 个答案