首页 > 解决方案 > RecyclerView 不滚动

问题描述

我有一个 RecyclerView 的问题:它不滚动,这是我的布局:

      <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardElevation="1dp">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:id="@+id/square3"
            android:src="@drawable/square"/>

        <LinearLayout
            android:layout_width="60dp"
            android:layout_height="wrap_content"
            android:id="@+id/lin"
            android:orientation="vertical">

            <TextView
                android:id="@+id/day"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/nameeOfMonthTable"/>

        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recicloEvent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginRight="26dp"
            android:layout_marginTop="20dp"
            android:layout_toRightOf="@+id/lin"
            android:layout_alignBottom="@+id/square3"
            android:layout_alignTop="@+id/square3"
            android:layout_marginBottom="25dp"
            android:paddingLeft="1dp"/>

        <View
            android:id="@+id/separatorDateRvCale2"
            android:layout_width="1dp"
            android:layout_alignTop="@+id/square3"
            android:layout_height="200dp"
            android:layout_alignBottom="@+id/square3"
            android:layout_alignLeft="@+id/recicloEvent"

            />

        <View
            android:id="@+id/separatorDateRvCale"
            android:layout_width="1dp"
            android:layout_alignTop="@+id/square3"
            android:layout_height="200dp"
            android:layout_alignBottom="@+id/square3"
            android:layout_alignLeft="@+id/recicloEvent"
            />


    </RelativeLayout>

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

这是另一个正确滚动的 RecyclerView 的适配器:上部 RecyclerView 在另一个 RecyclerView 内部(不正确滚动的那个) 问题只影响内表(即向上的那个)。我该如何解决这个问题?这是一个屏幕:回收站视图,问题影响在底部切割的 RecyclerView

标签: androidandroid-recyclerview

解决方案


尝试将整个布局放在 NestedScrollView 中,如下所示

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView 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"
    app:cardElevation="1dp">

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

        <ImageView
            android:id="@+id/square3"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:src="@drawable/square" />

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

            <View
                android:id="@+id/separatorDateRvCale2"
                android:layout_width="1dp"
                android:layout_height="200dp" />

            <View
                android:id="@+id/separatorDateRvCale"
                android:layout_width="1dp"
                android:layout_height="200dp" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recicloEvent"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="25dp"
                android:layout_marginRight="26dp"
                android:layout_marginTop="20dp"
                android:layout_toRightOf="@+id/lin"
                android:layout_weight="1"
                android:paddingLeft="1dp" />

            <LinearLayout
                android:id="@+id/lin"
                android:layout_width="60dp"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/day"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/nameeOfMonthTable"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

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

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

推荐阅读