在NestedScrollView Android中使用线性布局上的onClick时,滚动不起作用
我在一个NestedScrollView中包含了多个布局。但当我要滚动时,包含的部分不会滚动。我将这个布局加载到主布局中,主布局具有协调布局。所以我不明白到底出了什么问题。下面是我的代码,当我删除线性布局的点击事件时,所有包含的布局中都有onClick事件,它工作正常在NestedScrollView Android中使用线性布局上的onClick时,滚动不起作用,android,android-layout,material-design,android-support-library,nestedscrollview,Android,Android Layout,Material Design,Android Support Library,Nestedscrollview,我在一个NestedScrollView中包含了多个布局。但当我要滚动时,包含的部分不会滚动。我将这个布局加载到主布局中,主布局具有协调布局。所以我不明白到底出了什么问题。下面是我的代码,当我删除线性布局的点击事件时,所有包含的布局中都有onClick事件,它工作正常 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://s
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingTop="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="@color/AppPrimary"
android:gravity="center"
android:padding="20dp"
android:text="Demo"
android:textColor="@color/white" />
<include
layout="@layout/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp" />
<include
android:id="@+id/layout2"
layout="@layout/layout2" />
<include
layout="@layout/layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp" />
<include
android:id="@+id/layout3"
layout="@layout/layout3" />
<include
layout="@layout/layout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp" />
<include
android:id="@+id/layout5"
layout="@layout/layout5" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
下面是我的主要活动代码,这个片段将被附加到这里
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<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_width="match_parent"
android:layout_height="@dimen/scale_250dp"
android:fitsSystemWindows="true"
android: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"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/CollapsedTitleTextAppearance"
app:contentScrim="@color/AppPrimary"
app:expandedTitleTextAppearance="@style/ExpandedTitleTextAppearance"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/img_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="100dp"
android:scaleType="centerCrop"
android:src="@drawable/img_place_holder"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" />
<View
android:id="@+id/img_shadow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/drop_shadow" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:navigationIcon="@drawable/ic_home"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="@+id/img_slider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="@dimen/scale_20dp"
android:src="@drawable/ic_navigation" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<ListView
android:id="@+id/listView"
android:layout_width="@dimen/scale_200dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@color/AppPrimary"
android:choiceMode="singleChoice"
android:divider="@color/AppPrimaryDark"
android:dividerHeight="@dimen/scale_1dp"
android:headerDividersEnabled="false"
android:listSelector="@drawable/selector_background_listview"
android:overScrollMode="never"
android:scrollbars="none" />
</android.support.v4.widget.DrawerLayout>
包含的视图是什么类型的布局?它们也是滚动容器吗?不,它们的父视图是线性布局。@ThomasR。您想滚动包含的输入还是整个视图?布局中的某些内容包括获得焦点或触摸事件?我只想在嵌套的ScrollView区域中滚动。是的,此线性布局上存在触摸事件。那么,它可能会导致滚动出现任何缺陷@托马斯尔,当然可以。如果覆盖onDispatchTouchEvent或onTouchEvent,然后在包含的视图上返回true,则事件将被使用,并且不会传播到父视图。包含的视图是什么类型的布局?它们也是滚动容器吗?不,它们的父视图是线性布局。@ThomasR。您想滚动包含的输入还是整个视图?布局中的某些内容包括获得焦点或触摸事件?我只想在嵌套的ScrollView区域中滚动。是的,此线性布局上存在触摸事件。那么,它可能会导致滚动出现任何缺陷@托马斯尔,当然可以。如果覆盖onDispatchTouchEvent或onTouchEvent,然后在包含的视图上返回true,则该事件将被使用,并且不会传播到父视图。