当前位置: 首页 > 知识库问答 >
问题:

Android回收视图在scrollview[复制]

薛俊美
2023-03-14

我有

主视图

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

共有3个答案

丌官博文
2023-03-14

在您的代码中,您在滚动视图中有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:如果滚动视图也有其他子包括回收视图比你应该使用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>
易炳
2023-03-14

如果您无法滚动,则是因为这一行

android:nestedScrollingEnabled=“false”

将其更改为True,以便启用滚动:

android:nestedScrollingEnabled=“true”

韦熙云
2023-03-14

使用NestedScrollview而不是scrollview,并使用android:nestedScrollingEnabled=“false”用于回收商产品回收视图,但不同时使用这两种视图

    <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>
 类似资料:
  • 我能够从URL发送JSON响应,然后当我在RecyclerView上显示相同的响应时,得到的输出是空白的,但选项卡和导航抽屉仍然存在。运行该应用程序时也没有错误。我也在使用截击库。 问题:我在列出服务的RecylerView上没有得到任何输出。我会在这里贴出与RecyclerView相关的代码。另外,我已经在底部发布了堆栈跟踪。 serviceViewAdapter.java(适配器) fragm

  • 我在里面使用了。我还将设置为false for 支持较低的API

  • 我的循环可以在NestedScrollView中滚动。然而,这并不像往常一样顺利。谁能帮我修一下吗。 这是我的密码

  • 我刚开始在firebase工作。我设法上传了文本和图像,但是,我无法检索要显示在回收器视图中的图像,只能检索文本。我用的是毕加索依赖。我已经包括了我的主要活动。java类,该类负责显示从问题“我的适配器”中的firebase检索的回收器视图项。java类和模型类。我相信,在我将图像URI上载到firebase存储时,我可能犯了没有存储图像URI的错误,因此适配器无法检索图像位置。我想这可能是因为我

  • 嘿,我正在尝试将文本从回收器视图项目复制到剪贴板中,当我尝试在活动中执行此操作时,它的工作原理,但当我尝试查看者中的代码时,我得到了未解决的参考:CLIPBOARD_SERVICE错误这里是代码:

  • 我正在将Recyclerview与CardView一起使用我知道如何在列表视图上控制速度。但对于RecyclerView不是。 更新: 我用这个总结了吉尔的回答