Android 如何使回收器视图可滚动
我正在尝试使回收器视图在xml布局文件中可滚动 但它不会滚动 这是我试过的Android 如何使回收器视图可滚动,android,android-layout,android-recyclerview,Android,Android Layout,Android Recyclerview,我正在尝试使回收器视图在xml布局文件中可滚动 但它不会滚动 这是我试过的 <?xml version="1.0" encoding="utf-8"?> <layout xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<data class=".ProductsBinding">
<variable
name="productsViewModel"
type="com.xxx.xx.ProductsViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ProductsFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/products_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</layout>
你能建议一下如何让它工作吗
谢谢
R首先,如果您的子级只有RecyclerView,为什么要使用NestedScrollView 不管怎样,这个怎么样
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<data class=".ProductsBinding">
<variable
name="productsViewModel"
type="com.xxx.xx.ProductsViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ProductsFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/products_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</layout>
在NestedScrollView中添加linearLayout
CF]如果在双滚动视图中使用recycler视图,则recycler视图将提前生成所有项目。(您可以从RecycleView适配器上的onBindViewHolder检查日志。)此外,由于我们不回收项视图,我们失去了回收视图的最大优势,它可以通过重用视图提高内存效率,因此请务必记住这一点。如果你有很多物品,请避免使用它们。请尝试
NestedScrollView
的android:layout\u height=“wrap\u content”
,如果不起作用,也尝试android:nestedScrollingEnabled=“true”
在RecyclerView
@Zain我尝试过,但没有起作用,我在我的数据库中再次更新了xml文件question@Zain尝试过但不起作用您是否可以将android:fillViewport=“true”
添加到NestedScrollView
尝试过@Zain但不起作用通常您不需要NestedScrollView,而仅作为子级可滚动视图