Просмотр переработчика Android внутри прокрутки

у меня есть

ГЛАВНЫЙ ВИД

<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)


person pedroooo    schedule 30.09.2020    source источник


Ответы (3)


В вашем коде у вас есть 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, вам следует использовать вложенный прокрутку, как показано ниже:

<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>
person Keyur Nimavat    schedule 30.09.2020

Используйте 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>
person Wahdat Jan    schedule 30.09.2020

Если вы не можете прокрутить, это из-за этой строки

android:nestedScrollingEnabled="false".

Измените его на True, чтобы вы могли включить прокрутку:

android:nestedScrollingEnabled="true".

person Mateo Hervas    schedule 30.09.2020