【问题标题】:ScrollView slow scroll and items disappearingScrollView 缓慢滚动和项目消失
【发布时间】:2017-04-04 12:44:47
【问题描述】:

我正在尝试添加一个 ScrollView 来保存一个标题和一个 RecyclerView。

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/profile"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="?attr/colorPrimary">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/imageView"
            android:adjustViewBounds="true"
            android:cropToPadding="false" />


    </RelativeLayout>


    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:scrollbars="none"
        android:layout_alignParentLeft="true" />


    </RelativeLayout>

</ScrollView>

但是我在尝试这个时遇到了两个问题:

  • 相关布局 ID/配置文件正在消失。当我打开活动时,它会出现 1 秒钟然后消失。

  • RecyclerView 滚动太慢。

有什么想法吗?

【问题讨论】:

  • 将相对布局设为父级。并在其中制作 NestedScrollview。现在在其中移动其他布局和recyclerview
  • 为什么RecyclerViewScrollView 下??
  • @IntelliJAmiya 我想一起滚动标题(id/profile)和recyclerview。如果我不添加滚动视图,我将无法滚动标题。

标签: android android-layout android-recyclerview android-xml android-scrollview


【解决方案1】:

默认情况下,RecyclerView 有自己的滚动条,这与您的ScrollView 冲突。要修复它,请将ScrollView 更改为NestedScrollView

【讨论】:

  • @GabrielaDias 这是一个完美的答案。
  • @LuizFernandoSalvaterra 这是我们的职责:)。前进
  • 我加了:android.support.v4.widget.NestedScrollView 而不是ScrollView,但都还是一样,标题消失了,滚动仍然很慢;/
【解决方案2】:

将recyclerView放在XML中的NestedScrollView中

 <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <android.support.v7.widget.RecyclerView
                 android:id="@+id/recycler_pracstice_loaction"
                 android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" />
            </android.support.v4.widget.NestedScrollView>

在活动中:

recyclerView.setNestedScrollingEnabled(false);

当然,你会得到你想要的。这将解决您的 Recyclerview 滚动问题

在您的活动中添加以下代码,它将解决您的自动滚动问题。

recyclerView.setFocusable(false);

【讨论】:

  • 感谢您的回答。我在哪里可以添加我的标题?
  • 等几分钟我给你答案,你面临的自动滚动。
  • 如果我的回答对您有帮助,请将我的回答标记为正确,谢谢。
【解决方案3】:
   recylerview.setNestedScrollingEnabled(false);

请设置recylerview的这个属性。

【讨论】:

    【解决方案4】:

    你可以看看这个项目。它不是图书馆。它是一个演示代码...我想你在寻找什么

    在这里查看https://github.com/kmshack/Android-ParallaxHeaderViewPager

    【讨论】:

      【解决方案5】:

      将您的滚动视图更改为 NestedScrollView。

      相关布局 ID/配置文件正在消失。当我打开 活动它会出现 1 秒然后消失。

      您的 recyclerview 正在加载 itens,将鼠标悬停在 relativeLayout 中,因此,将其添加到您的 recyclerview 中:

      android:layout_below="@+id/profile"
      

      recyclerview 滚动太慢了。

      只需在您的活动中添加以下代码:

      recylerview.setNestedScrollingEnabled(false);
      

      【讨论】:

        猜你喜欢
        • 2023-04-02
        • 2015-06-20
        • 1970-01-01
        • 2021-09-04
        • 1970-01-01
        • 2016-02-20
        • 2021-06-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多