NestedScrollView 中的横向 RecyclerView 无法垂直滚动

3

我尝试了这个的每一个组合,有些人说这是一个bug,但我认为可能是我漏掉了一些小细节。使用以下XML,我无法滚动,只有水平滚动起作用。

我有一个可以左右拖动的侧滑RecyclerView,但页面上有更多的项目无法容纳,因此需要ScrollView。

起初我想要一个可折叠的工具栏,但当我添加CoordinatorLayout时,活动就变成了空白。

我的XML:

<android.support.constraint.ConstraintLayout 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"
    android:nestedScrollingEnabled="true"
    app:layout_constraintTop_toBottomOf="@+id/scrollv"
    tools:context="com.wearecatchapp.blueandwhite.catchapp_droid.EventDetailActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/detail_toolbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:elevation="2dp"
        android:minHeight="60dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

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

            <TextView
                android:id="@+id/evt_title"
                fontPath="fonts/PanameFY.otf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textAlignment="center"
                android:textColor="@color/black"
                android:textSize="30sp" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:padding="2dp"
                    android:text="Organizer's level:"
                    android:textAlignment="center"
                    android:textColor="@color/black"
                    android:textSize="12sp" />

                <ImageView
                    android:id="@+id/org_level"
                    android:layout_width="60dp"
                    android:layout_height="16dp"
                    android:layout_gravity="center_vertical" />
            </LinearLayout>

            <TextView
                android:id="@+id/optional_title"
                fontPath="fonts/PanameFY.otf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:padding="2dp"
                android:textAlignment="center"
                android:textColor="@color/black"
                android:textSize="24sp"
                android:visibility="gone" />

        </LinearLayout>

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


    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/detail_toolbar">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <ImageView
                android:id="@+id/activity_image"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"

                app:srcCompat="@color/black" />

            <TextView
                android:id="@+id/month"
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:text="NOV"
                android:textAlignment="center"
                android:textColor="@android:color/holo_red_light"
                android:textSize="18sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/activity_image" />

            <TextView
                android:id="@+id/day"
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="2dp"
                android:text="15"
                android:textAlignment="center"
                android:textColor="@color/black"
                android:textSize="24sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/month" />

            <TextView
                android:id="@+id/starts"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:text="Starts"
                android:textColor="@color/black"
                android:textSize="18sp"
                app:layout_constraintLeft_toRightOf="@+id/month"
                app:layout_constraintTop_toBottomOf="@+id/activity_image" />

            <TextView
                android:id="@+id/ends"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="7dp"
                android:text="Ends"
                android:textColor="@color/black"
                android:textSize="18sp"
                app:layout_constraintLeft_toRightOf="@+id/day"
                app:layout_constraintTop_toBottomOf="@+id/starts" />

            <TextView
                android:id="@+id/start_date"
                fontPath="fonts/AvenirNext-Medium.ttf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="42dp"
                android:layout_marginStart="42dp"
                android:layout_marginTop="8dp"
                android:text=" 18:10   Wed, Nov 15"
                android:textColor="@color/black"
                android:textSize="18sp"
                app:layout_constraintLeft_toRightOf="@+id/starts"
                app:layout_constraintTop_toBottomOf="@+id/activity_image" />

            <TextView
                android:id="@+id/textView34"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dp"
                android:layout_marginStart="50dp"
                android:layout_marginTop="7dp"
                android:textColor="@color/black"
                android:textSize="18sp"
                app:layout_constraintLeft_toRightOf="@+id/ends"
                app:layout_constraintTop_toBottomOf="@+id/start_date" />

            <View
                android:id="@+id/view10"
                id="@+id/view8"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginTop="16dp"
                android:background="@color/thegray"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/linearLayout2" />

            <View
                android:id="@+id/view9"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginTop="9dp"
                android:background="@color/thegray"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView34" />

            <LinearLayout
                android:id="@+id/linearLayout"
                android:layout_width="397dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dp"
                android:orientation="horizontal"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView34">

                <ImageView
                    android:id="@+id/requests_image"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_weight="1"
                    app:srcCompat="@drawable/requestsicon" />

                <ImageView
                    android:id="@+id/invite_image"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_weight="1"
                    app:srcCompat="@drawable/invitefriends" />

                <ImageView
                    android:id="@+id/recommend_image"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_weight="1"
                    app:srcCompat="@drawable/recommend" />

                <ImageView
                    android:id="@+id/share_image"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_weight="1"
                    app:srcCompat="@drawable/shareblue" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout2"
                android:layout_width="396dp"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/linearLayout">

                <TextView
                    android:id="@+id/requests_text"
                    fontPath="fonts/avenir-next-bold.ttf"
                    android:layout_width="24dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Requests"
                    android:textAlignment="center"
                    android:textColor="@color/black"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/invite_friends_text"
                    fontPath="fonts/avenir-next-bold.ttf"
                    android:layout_width="24dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Invite friends"
                    android:textAlignment="center"
                    android:textColor="@color/black"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/recommend_event_text"
                    fontPath="fonts/avenir-next-bold.ttf"
                    android:layout_width="24dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Recommend"
                    android:textAlignment="center"
                    android:textColor="@color/black"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/share_text"
                    fontPath="fonts/avenir-next-bold.ttf"
                    android:layout_width="24dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Share"
                    android:textAlignment="center"
                    android:textColor="@color/black"
                    android:textSize="12sp" />
            </LinearLayout>

            <TextView
                android:id="@+id/status_text"
                fontPath="fonts/avenir-next-bold.ttf"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:paddingLeft="8dp"
                android:textColor="@color/dark_gray"
                android:textSize="20sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view10" />

            <ImageView
                android:id="@+id/is_for"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="6dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/status_text"
                app:srcCompat="@drawable/maleandfemale" />

            <TextView
                android:id="@+id/going"
                fontPath="fonts/AvenirNext-Medium.ttf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="15dp"
                android:text="going"
                android:textColor="@color/black"
                app:layout_constraintLeft_toRightOf="@+id/is_for"
                app:layout_constraintTop_toBottomOf="@+id/status_text" />

            <TextView
                android:id="@+id/more_togo"
                fontPath="fonts/AvenirNext-Medium.ttf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginStart="20dp"
                android:layout_marginTop="15dp"
                android:text="TextView"
                android:textColor="@color/black"
                app:layout_constraintLeft_toRightOf="@+id/hor_view"
                app:layout_constraintTop_toBottomOf="@+id/status_text" />

            <View
                android:id="@+id/hor_view"
                class="android.support.v4.widget.Space"
                android:layout_width="1dp"
                android:layout_height="30dp"
                android:layout_marginLeft="35dp"
                android:layout_marginStart="35dp"
                android:layout_marginTop="8dp"
                android:background="@color/dark_gray"
                app:layout_constraintLeft_toRightOf="@+id/going"
                app:layout_constraintTop_toBottomOf="@+id/status_text" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/participants_list"
                android:layout_width="0dp"
                android:layout_height="117dp"
                android:layout_marginTop="12dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/hor_view" />

            <View
                android:id="@+id/view16"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginTop="8dp"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/participants_list" />

            <TextView
                android:id="@+id/textView47"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="17dp"
                android:text="Costs"
                android:textSize="18sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view16" />

            <TextView
                android:id="@+id/cost_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginTop="17dp"
                android:text="TextView"
                android:textSize="18sp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view16" />

            <View
                android:id="@+id/view19"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginTop="55dp"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view16" />

            <TextView
                android:id="@+id/cost_title_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="13dp"
                android:textSize="18sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view19" />

            <View
                android:id="@+id/view20"
                android:layout_width="0dp"
                android:layout_height="1px"
                android:layout_marginTop="16dp"
                android:background="@color/thegray"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view19" />

            <ImageView
                android:id="@+id/imageView15"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:padding="8dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view20"
                app:srcCompat="@drawable/pinblue" />

            <TextView
                android:id="@+id/textView50"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="7dp"
                android:layout_marginStart="7dp"
                android:layout_marginTop="16dp"
                android:text="Event location"
                android:textColor="@color/colorPrimary"
                android:textSize="18sp"
                app:layout_constraintLeft_toRightOf="@+id/imageView15"
                app:layout_constraintTop_toBottomOf="@+id/view20" />

            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:padding="8dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView50"
                app:srcCompat="@drawable/background" />
        </android.support.constraint.ConstraintLayout>

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


    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_marginBottom="29dp"
        android:layout_marginEnd="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginStart="40dp"
        app:cardBackgroundColor="@color/colorPrimary"
        app:cardCornerRadius="18dp"
        app:cardElevation="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="REQUEST TO JOIN"
            android:textColor="@android:color/white"
            android:textSize="14dp" />
    </android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>

有人能不能好心解释一下这个东西啊。


在onCreate方法中添加这行代码 mRecyclerView.setNestedScrollingEnabled(false); - Harish Penta
3个回答

2

尝试在您的内部RecyclerView中添加setNestedScrollingEnabled(false)

https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

setNestedScrollingEnabled

启用或禁用此视图的嵌套滚动。

如果将此属性设置为true,则允许该视图与当前层次结构中的兼容父视图启动嵌套滚动操作。如果此视图未实现嵌套滚动,则此操作无效。在进行嵌套滚动时禁用嵌套滚动具有停止嵌套滚动的效果。


0

1) XML

Android.support.v4.widget.NestedScrollView 内部使用LinerLayout

2) recyclerView = (RecyclerView)view.findViewById(R.id.recyclerview_main); recyclerView.setNestedScrollingEnabled(false);


0

如果有人仍然遇到这个问题,请注意以下两点:

  1. 你的NestedScrollView高度应该设置为match_parent。如果你正在使用ConstraintLayout中的NestedScrollView,你可以通过以下代码实现:

    android:layout_height="0dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    
  2. 在你的RecyclerView中添加下面这行代码:

    android:nestedScrollingEnabled="false"

我希望它能为他人节省时间。


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