Android 嵌套滚动框内的可单击卡片视图不';不触发滚动

Android 嵌套滚动框内的可单击卡片视图不';不触发滚动,android,android-design-library,android-collapsingtoolbarlayout,android-coordinatorlayout,android-appbarlayout,Android,Android Design Library,Android Collapsingtoolbarlayout,Android Coordinatorlayout,Android Appbarlayout,我有一个带有坐标布局的布局,AppBarLayout和NestedScrollView,在NestedScrollView中我有多个CardView,在我将CardView设置为可单击之前,一切正常,然后如果我在CardView中启动滚动,则滚动不起作用 这是我的布局: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xml

我有一个带有坐标布局的布局,AppBarLayout和NestedScrollView,在NestedScrollView中我有多个CardView,在我将CardView设置为可单击之前,一切正常,然后如果我在CardView中启动滚动,则滚动不起作用

这是我的布局:

<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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="256dp"
    android:layout_width="match_parent"
    app:contentScrim="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary">
        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"/>
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedScroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_gravity="fill_vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="0dp"
            app:cardUseCompatPadding="true">
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <View
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:background="@color/primary" />
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="4dp"
                    android:paddingLeft="7dp"
                    android:paddingRight="7dp"
                    android:paddingBottom="7dp">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:lines="1"
                        android:includeFontPadding="false"
                        android:text="Title1"
                        style="@android:style/TextAppearance.Medium" />
                    <TextView
                        android:lines="2"
                        android:text="Description 1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />
                </LinearLayout>
            </LinearLayout>
        </android.support.v7.widget.CardView>
       ...
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

...

当ScrollView没有填充内容时,问题就出现了。我认为这是安卓系统中一个非常奇怪的错误

“解决方案”


问题似乎与此处相同:

这是解决您的问题的一种方法


但是你也应该为你的
CardView
使用
setPreventCornerOverlap(false)
,以避免CardView出现问题,正如人们所指出的,问题是当
CardView
完全位于屏幕内时,它不会触发从卡上滚动。在
折叠工具栏布局
中的视图中滚动仍然有效


我的解决方案是将android:layout_marginBottom=“100dp”添加到
CardView
中,这样底边就可以在屏幕外滚动了。

对于开放的bounty+50来说很遗憾,但这绝对是一个副本-删除bounty和标记副本。情况不同,虽然从标题上看起来确实如此,但我认为真正的问题是,当我将CardView设置为可点击时,触摸事件不会出现在scrollview上。我确实在scrollview中使用了fill_垂直布局,这为我解决了一些问题,但它没有用可点击元素修复滚动可能你是对的,但我们可能需要覆盖拦截触摸事件,使其不传播到返回true的子视图。在哪个视图中,我应该处理拦截触摸事件?我给你的另一页中的答案的所有者评论说,他确实没有解决问题,并且“看起来问题出在CollasingToolbar上,因为如果我们删除了CollasingToolbar,它就可以正常工作了现在我们有两个选择:等待Google解决所有这些多个bug,或者尝试实现一些东西。对于最后一个假设,我认为覆盖的方法是onInterceptTouchEvent,您可以从这个类开始
FixedScrollingViewBehavior
,您可以在这里找到已经解决了一些问题的方法。这可以修复滚动,但上面的元素会滚动到窗口之外。是的。我想问题是关于滚动的问题。。如果其他视图出现在窗口之外,则听起来您的配置中还有其他一些错误。我已尝试进行适当的修复,但无法修复。谷歌的新课程太复杂了。使用RecyclerView更容易。在我今天看来(!)整个库都是垃圾。我在查找/修复错误上浪费了很多时间,最后没有得到正确的结果。:/可能是因为我不是专业人士,但在升级到22.2.1版之后,NavigationView的设置图标(新的可绘制)不再工作了。洛加特也在发射垃圾。。非常非常奇怪。也许我们必须等到22.2.x(?)…直到23.0.1这个错误仍然存在!!而且没有很难修复的源代码。
<android.support.design.widget.CoordinatorLayout
    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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="256dp"
        android:layout_width="match_parent"
        app:contentScrim="?attr/colorPrimary"
        android:fitsSystemWindows="true"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_gravity="fill_vertical">

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

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:cardCornerRadius="0dp"
                app:cardUseCompatPadding="true"
                android:foreground="?android:attr/selectableItemBackground"
                android:clickable="true">

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

                    <View
                        android:layout_width="80dp"
                        android:layout_height="80dp"
                        android:background="#cdcdcd"
                        android:clickable="true"/>

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingTop="4dp"
                        android:paddingLeft="7dp"
                        android:paddingRight="7dp"
                        android:paddingBottom="7dp">

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:lines="1"
                            android:includeFontPadding="false"
                            android:text="Title1"
                            style="@android:style/TextAppearance.Medium"/>

                        <TextView
                            android:lines="2"
                            android:text="Description 1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            />
                    </LinearLayout>
                </LinearLayout>
            </android.support.v7.widget.CardView>

            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1000dp"
            android:orientation="vertical"
            android:layout_margin="4dp"
            android:background="#c1c1c1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20pt"
                android:text="some content..."/>
        </LinearLayout>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>