android - 在 android 的 nestedscrollview 中使用 3 个 recyclerviews 时滚动不流畅

标签 android android-layout android-viewpager android-recyclerview android-coordinatorlayout

我在一个布局文件中有三个 recyclerviews,它们具有水平对齐的布局管理器,这些 recyclerviews 在 nestedscrollview 内,我也将三个 recyclerviews 中的每一个的 nestedscrolling 设置为 false。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/frameLayout"
    android:background="@drawable/background">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

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

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="5dp"
                        android:text="FREE MOVIES"
                        android:textStyle="bold"
                        android:textSize="18sp"
                        android:textColor="@color/colorAccent"
                         />
                    <view
                        android:id="@+id/recycler_view"
                        class="android.support.v7.widget.RecyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true" />
            </LinearLayout>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:text="PREMIUM MOVIES"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"
                    android:textSize="18sp" />

                <view
                    android:id="@+id/recycler_view1"
                    class="android.support.v7.widget.RecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true" />

            </LinearLayout>


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

                <TextView
                    android:id="@+id/tvTrending"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:text="PACKAGES"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"
                    android:textSize="18sp" />

                <view
                    android:id="@+id/recycler_view2"
                    class="android.support.v7.widget.RecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:dividerHeight="10.0sp" />
            </LinearLayout>

        </LinearLayout>

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

    <ProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_gravity="center"/>

</FrameLayout>

这是我从 MainActivity 的 viewpager 调用的 fragment 的布局。它有这样的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    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"
    tools:context="com.newitventure.musicnepal.MainActivity">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/tabanim_appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


            <include
                android:id="@+id/tool_bar"
                layout="@layout/toolbar" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMaxWidth="0dp"
                android:background="@color/colorPrimaryDark"
                app:tabGravity="fill"
                app:tabTextAppearance="@style/MyCustomTextAppearance"
                app:tabMode="scrollable" />

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/tabanim_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="50dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    </android.support.design.widget.CoordinatorLayout>

    <LinearLayout
        android:id="@+id/gad_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:orientation="horizontal"
        android:visibility="visible">

    </LinearLayout>
</RelativeLayout>

问题是尝试在此布局中滚动时滚动不流畅。尝试垂直和水平滚动时,它变得非常迟钝。这可能是什么问题?

最佳答案

这解决了我的问题:

mRecyclerView.setNestedScrollingEnabled(false);

详情:

Recyclerview inside ScrollView not scrolling smoothly

关于android - 在 android 的 nestedscrollview 中使用 3 个 recyclerviews 时滚动不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38456530/

相关文章:

android - 使用 Image above Text 创建一个按钮而不是 drawableTop()

android - 基于具有空值的对象构建字符串

来自非 Activity 类的非 Activity 类中的Android getResource?

Android SpannableStringBuilder 在Textview中添加Editetxtview

java - 如何为我的所有 Activity 创建自定义标题栏?

android - 仅在从服务器返回的数据更改后更新缓存数据。

android - 在 kotlin Android 中以编程方式生成的 View 的数据绑定(bind)

android - 如何构建带有多行标题的警报对话框?

java - onSwipe 事件未在 ViewPager 内触发

android - 防止选择 viewPager 最后一页