android - NestedScrollView 内的水平 RecyclerView,无法垂直滚动

标签 android android-recyclerview horizontalscrollview android-nestedscrollview

我尝试了这一切的组合,有些人说这是一个错误,但我认为这是我遗漏的一些小问题。使用以下 XML,我根本无法滚动,只能水平滚动。

我有一个横向滚动的 RecyclerView,我可以左右拖动它,但是页面中的 I 项多于容纳不下的内容,因此需要 ScrollView。

起初我的目标是一个可折叠的工具栏,但是当我添加 CoordinatorLayout 时, Activity 只是空白。

我的 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>

看在上帝的份上,有人请给我解释一下这狗屎。

最佳答案

尝试将 setNestedScrollingEnabled(false) 添加到您的内部 recyclerview。

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

setNestedScrollingEnabled

Enable or disable nested scrolling for this view.

If this property is set to true the view will be permitted to initiate nested scrolling operations with a compatible parent view in the current hierarchy. If this view does not implement nested scrolling this will have no effect. Disabling nested scrolling while a nested scroll is in progress has the effect of stopping the nested scroll.

关于android - NestedScrollView 内的水平 RecyclerView,无法垂直滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46869754/

相关文章:

Android - RecyclerView - 如何暂时阻止滚动?

java - android java onClick 无法执行 Activity 的方法

android - 在 RecyclerView 中添加删除按钮

android - 如何在Android中获取触发事件的 View ?

android - Kotlin 和 Android 数据绑定(bind)

java - Android 未处理的异常 : org. json.JSONException with ion

java - JSONArray在android中抛出内存异常

android - 如何制作重复(圆形)水平 ScrollView ?

java - 使RelativeLayout在水平 ScrollView 中不可滚动

android Horizo​​ntalScrollView布局组件方向