Recycle View 上的加速滚动

5

我有一个RecycleView,其中包含一系列的CardsViews。由于我有一个可折叠的标题栏,所以RecycleView位于NestedScrollView中。

滚动不是加速的,当我从屏幕上拿开手指时,它停止滚动,我想要加速滚动。

这些是我的布局。

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".articles.ArticlesActivity"
    tools:showIn="@layout/activity_articles"
    >


    <android.support.v7.widget.RecyclerView
        android:id="@+id/articles_lista"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fadeScrollbars="true"
        android:scrollbars="vertical"
        />

</android.support.v4.widget.NestedScrollView>

我的 CardView 布局容器。
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/articles_card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="6dp"
    card_view:cardUseCompatPadding="true"
    card_view:cardPreventCornerOverlap="true"
    android:layout_marginTop="0dp"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    card_view:cardElevation="5dp"

    android:overScrollMode="always"
    android:fadeScrollbars="true">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:id="@+id/article_card_title"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000"/>

    </LinearLayout>

</android.support.v7.widget.CardView>

以下是JAVA代码:

        RecyclerView recyclerView = (RecyclerView)findViewById(R.id.articles_lista);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        ArticlesAdapter adapter = new ArticlesAdapter(Mock.getNoticias(1L), this);
        recyclerView.setAdapter(adapter);

感谢您的选择。
编辑:
我的新布局正在运行,看起来像这样:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="newser.sab.com.newser.articles.ArticlesActivity2"
    tools:showIn="@layout/app_bar_articles2">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/articles_lista"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fadeScrollbars="true"
        android:scrollbars="vertical"
        />

</RelativeLayout>

我有完全相同的问题,有解决方案吗? - AVEbrahimi
2个回答

0

工作中是否更改布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="newser.sab.com.newser.articles.ArticlesActivity2"
tools:showIn="@layout/app_bar_articles2">

<android.support.v7.widget.RecyclerView
    android:id="@+id/articles_lista"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadeScrollbars="true"
    android:scrollbars="vertical"
    />


0
这是因为您将RecyclerView放在ScrollView中。 因此,为了加快滚动速度,请在RecyclerView标签中的xml文件中添加此行。
android:nestedScrollingEnabled="false"

或者以动态方式添加此行到您的Java文件中。
recyclerView.setNestedScrollingEnabled(false);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接