我在一个 NestedScrollView 中有多个包含的布局。但是当我要滚动时,包含的部分不会滚动。我将此布局加载到具有 CoordinatorLayout 的主布局中。所以出了什么问题我无法理解。下面是我的代码,所有包含的布局中都有 onClick 事件当我删除我的线性布局的点击事件时,它工作正常。
<?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>