Android 滚动视图中的回收站视图
Android recycler view inside on scrollview
我有
主视图
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</ScrollView>
在我的模板适配器上,我有另一个用于子视图的回收器适配器
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/title_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:background="@color/GRAY"
android:text="TextView" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_for_specification_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:nestedScrollingEnabled="false"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
代码有效,但是当用户在 android 设备上滚动时,父 scrollView 不允许我滚动回收站视图 (1)
如果您无法滚动,那是因为这条线
android:nestedScrollingEnabled="false"
.
将其更改为 True,以便启用滚动:
android:nestedScrollingEnabled="true"
.
使用 NestedScrollview 而不是 scrollview 并使用 android:nestedScrollingEnabled="false"
作为 recycler_products recyclerview 而不是两者都使用
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</androidx.core.widget.NestedScrollView>
在你的代码中,滚动视图中有 recylerview,这是错误的。
选项 1: 如果滚动视图除了删除它之外没有任何其他子视图,只需使用 recyclerview 并删除 android:nestedScrollingEnabled="false
您的主视图代码如下所示;
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
选项 2: 如果滚动视图还有其他子视图,包括 recyclerview,您应该像下面的代码一样使用 nestedscrollview:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<ImageView
android:id="@+id/sellerProduct"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:src="@drawable/iphone"
android:scaleType="fitXY"
android:contentDescription="@string/app_name" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:nestedScrollingEnabled="false
android:id="@+id/productList"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
我有
主视图
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</ScrollView>
在我的模板适配器上,我有另一个用于子视图的回收器适配器
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/title_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:background="@color/GRAY"
android:text="TextView" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_for_specification_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:nestedScrollingEnabled="false"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
代码有效,但是当用户在 android 设备上滚动时,父 scrollView 不允许我滚动回收站视图 (1)
如果您无法滚动,那是因为这条线
android:nestedScrollingEnabled="false"
.
将其更改为 True,以便启用滚动:
android:nestedScrollingEnabled="true"
.
使用 NestedScrollview 而不是 scrollview 并使用 android:nestedScrollingEnabled="false"
作为 recycler_products recyclerview 而不是两者都使用
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
/>
</androidx.core.widget.NestedScrollView>
在你的代码中,滚动视图中有 recylerview,这是错误的。
选项 1: 如果滚动视图除了删除它之外没有任何其他子视图,只需使用 recyclerview 并删除 android:nestedScrollingEnabled="false
您的主视图代码如下所示;
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
选项 2: 如果滚动视图还有其他子视图,包括 recyclerview,您应该像下面的代码一样使用 nestedscrollview:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<ImageView
android:id="@+id/sellerProduct"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:src="@drawable/iphone"
android:scaleType="fitXY"
android:contentDescription="@string/app_name" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:nestedScrollingEnabled="false
android:id="@+id/productList"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>