我内部有CoordinatorLayout
:AppBarLayout
,CollapsingToolbarLayout
(ImageView
和toolbar
)和NestedScrollView
。
在NestedScrollView
内,我有HorizontalScrollView
。当我水平滚动HorizontallScrollView
我的NestedScrollView
捕获输入作为垂直滚动而四次只捕获一次水平滚动工作正常。我该如何解决?
我对普通ScrollView
没有任何问题。
这是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<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/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="230dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:id="@+id/main.backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/test_primi"
app:layout_collapseMode="parallax"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/main.toolbar"
android:layout_width="match_parent"
android:layout_height="120dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
>
<LinearLayout
android:id="@+id/linear_layout_titolo_toolbar_primi"
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="horizontal"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:onClick="backToRicette"
android:padding="8dp"
android:src="@drawable/icona_freccia_back_bianca"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="18dp"
android:fontFamily="@font/roboto_medium"
android:gravity="start|center"
android:text="Primi"
android:textColor="@color/titoliToolbar"
android:textSize="@dimen/dimensioneTitoliToolbar"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_below="@id/linear_layout_titolo_toolbar_primi"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/background_layout_bordi_radius"
android:elevation="2dp"
>
<ImageView
android:id="@+id/icona_search_action_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="11dp"
android:src="@drawable/ic_search_black_96"
/>
<EditText
android:id="@+id/edit_text_cerca_ricette"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:ems="10"
android:fontFamily="@font/roboto_medium"
android:hint="Cerca"
android:inputType="textPersonName"
android:paddingLeft="8dp"
android:textColor="@color/corpoText"
android:textColorHint="@color/hintText"
android:textSize="20dp"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view_ricette_primi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:addStatesFromChildren="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/body"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/linear_layout_ricette_top_10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/background_layout_bordi_radius"
android:elevation="2dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/text_view_top_10_ricette"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/roboto_medium"
android:text="Top 10 Primi"
android:textColor="@color/titoli"
android:textSize="@dimen/dimensioneTitoli"
/>
<HorizontalScrollView
android:id="@+id/horizontal_scroll_view_top_10_ricette"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbars="none"
>
<!-- Here is an horizontal linear layout with 10 images. -->
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>