ScrollView不能惯性滑动。滚动缓慢。

5

我有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:fillViewport="true">

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

        <LinearLayout
            android:id="@+id/datatransfer_measure_list_layout_no_data"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/datatransfer_measure_list_textview_no_data"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginEnd="40dp"
                android:layout_marginStart="40dp"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:padding="5dp"
                android:text="@string/measure_data_empty"
                android:textColor="@color/textcolorprimary"
                android:textSize="18sp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_gravity="center"
                android:layout_marginBottom="20dp"
                android:layout_marginEnd="20dp"
                android:layout_marginStart="20dp"
                android:background="@android:color/darker_gray"
                android:importantForAccessibility="no" />
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/datatransfer_measure_list_row_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:clipToPadding="false"
            android:importantForAccessibility="no"
            android:paddingBottom="5dp"
            android:textColor="@color/textcolorprimary" />

        <Button
            android:id="@+id/datatransfer_measure_list_button_send"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="10dp"
            android:layout_marginEnd="40dp"
            android:layout_marginStart="40dp"
            android:background="@drawable/custom_button_ok"
            android:gravity="center"
            android:padding="10dp"
            android:text="@string/common_save"
            android:textColor="@drawable/custom_button_positive_text_color"
            android:textSize="20sp" />

        <Button
            android:id="@+id/datatransfer_measure_list_button_reset"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:layout_marginEnd="40dp"
            android:layout_marginStart="40dp"
            android:background="@drawable/custom_button_cancel"
            android:gravity="center"
            android:padding="10dp"
            android:text="@string/common_cancel"
            android:textColor="@drawable/custom_button_negative_text_color"
            android:textSize="20sp" />
    </LinearLayout>
</ScrollView>

这个布局基本上分为三部分。首先是一个只包含文本视图的布局,用于在没有数据时显示。当有数据时,它将变得不可见。

第二部分是我的recyclerview,只有设置了一些数据才会显示出来。

最后一部分是两个按钮。我在这个布局中遇到的问题是滚动非常缓慢。我不是说卡顿或类似的情况。我只能将视图滚动一个小部分,而不像其他滚动视图那样可以轻松地滑动视图使其自动滚动。我不知道这个布局与其他布局有什么不同,也不知道为什么此处的滚动视图运行方式与其他布局不同。是否有什么阻止滚动视图自动滚动的东西?

1个回答

15

你的RecyclerviewScrollView发生冲突,这就是为什么滚动不流畅的原因。

尝试禁用recyclerview的滚动。

RecyclerView recyclerView = (RecyclerView)findViewById(R.id.datatransfer_measure_list_row_parent);
recyclerView.setNestedScrollingEnabled(false)

1
那就是它。谢谢! - Mulgard

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