屏幕的高度不够,因为一个屏幕上有很多包含两个回收站视图的项目。所以我试图在嵌套滚动视图中有一个子视图。但是,所有物品都一次装载,否则回收商不会回收。
所以我阅读了其他文章并尝试过,但它对我不起作用。
例如添加app:layout_behavior="@string/appbar_scrolling_view_behavior"
或mRecyclerView.setNestedScrollingEnabled(false);
如果你知道怎么做,请告诉我。谢谢阅读。
这是我的java代码
myDataset = new ArrayList<>();
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.map_recycler_view);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(mcontext);
mLayoutManager.setAutoMeasureEnabled(true);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new MyAdapter(this);
mAdapter.setLinearLayoutManager(mLayoutManager);
mAdapter.setRecyclerView(mRecyclerView);
mRecyclerView.setAdapter(mAdapter);
Run Code Online (Sandbox Code Playgroud)
这是我的 xml 代码
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="180dp">
<fragment
android:id="@+id/googleMap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/tag_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layoutManager="LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/map_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:nestedScrollingEnabled="false">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
这是我的适配器代码,太多了,所以我上传了相关部分,它在到达回收视图底部时添加了一个新项目。
public …Run Code Online (Sandbox Code Playgroud) android infinite-scroll android-recyclerview nestedscrollview