19

Ich habe ein Layout mit einem CoordinatorLayout und AppBarLayout und einem NestedScrollView, in der NestedScrollView habe ich mehrere CardViews, alles funktioniert ok, bis ich die CardViews anklickbar sein, dann wenn ich starte ein Bildlauf in einem CardView, Bildlauf funktioniert nicht.Clickable CardView in NestedScroll löst kein Scrollen

Das ist mein Layout:

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

+3

Es ist schade für die offene Kopfgeld +50, aber das ist definitiv ein Duplikat von http://StackOverflow.com/Questions/31136740/Scroll-doesnt-Work-in-NestedScrollview-When-try-to-Scroll- from-views-with-click - Entfernen Sie Kopfgeld und markieren Sie das Duplikat. – Davidea

+2

Es ist nicht der gleiche Fall, obwohl es aus dem Titel scheint, dass es ist, ich denke, das eigentliche Problem hier ist, dass, wenn ich die Kartenansichten als anklickbar, dann das Touch-Ereignis nicht bis zum Scrollview Blase. Ich habe das fill_vertical-Layout in der Scrollview, und das behebt einige Probleme für mich, aber es nicht die Schriftrolle mit den anklickbaren Elementen – Escobar5

+1

Vielleicht haben Sie Recht, aber wahrscheinlich müssen wir Overcept Touch-Ereignis auf Nein zu propagieren weitergegeben werden zur Kinderansicht, die wahr zurückgibt. – Davidea

Antwort

7

Das Problem ans Tageslicht kommt, wenn die Scroll nicht mit Inhalt gefüllt ist. Ich denke, es ist ein sehr seltsamer Fehler in Android.

Die 'Lösung' ..

enter image description here

<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> 
+0

Dies behebt das Scrollen, aber die oberen Elemente scrollen über das Fenster hinaus. –

+0

Ja. Ich denke, die Frage bezieht sich auf das Scroll-Problem. Wenn andere Ansichten außerhalb des Fensters erscheinen, dann scheint es, als gäbe es noch einige andere Fehler in Ihrer Konfiguration. –

+0

Das ist wirklich seltsam, ich denke, es ist ein Android-Bug, Ihre Lösung scheint es zu beheben, leider macht es die Ansichten über das Fenster scrollen, wie @FedorKazakov sagt. – Escobar5

0

Wie die Leute bemerkt haben, ist das Problem, wenn der CardView sitzt vollständig innerhalb des Bildschirms wird es nicht Scrollen von der Karte auslösen. Scrollen funktioniert immer noch von Ansichten innerhalb der CollapsingToolbarLayout.

Meine Lösung war, android:layout_marginBottom="100dp" zu CardView hinzuzufügen, so dass die untere Kante Offscreen ist und so Scrollen ermöglicht.