28

Verwenden Koordinator Layout auf meiner Aktivitätsseite. Da ist ListView unterhalb der App-Leiste. Aber es funktioniert nicht, wenn ich ListView anstelle von NestedScrollView verwende. Und wenn ich ListView in NestedScrollView, erweitert ListView nichtListView expandiert nicht in NestedScrollView

+2

http://stackoverflow.com/a/6211286 – Sree

Antwort

28

Damit die CoordinatorLayout richtig funktioniert, müssen Sie das scrollende Kind zu implementieren NestedScrollingChild. Solche Klassen sind NestedScrollView und RecyclerView.

Um es kurz zu sagen - nur ein RecyclerView für eine Rolle im Inhalt verwenden und es wird korrekt funktionieren :)

P. S. Als Nebenbemerkung sehe ich keinen Grund, warum Sie eine ListView nicht mehr verwenden würden. Ich weiß, es ist eine Angewohnheit und es ist einfacher zu installieren (weil Sie es oft getan haben), aber die Verwendung eines RecyclerView ist der empfohlene Weg sowieso.

+1

Ich sehe nicht ein Fastscroll und Abschnitt Adapterimplementierung für Recycler Ansicht noch – sha

+1

Wie kann ich erweiterbare Listenansicht implementieren –

+6

RecyclerView nicht Behandle den CursorAdapter. Dies könnte ein guter Grund sein! – Blodhgard

56

können Sie es beheben, wenn Sie addtributeandroid:fillViewport="true" in android.support.v4.widget.NestedScrollView hinzufügen :). Das ist mein Code.

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="none" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:fillViewport="true" 
    > 
    <ListView 
     android:id="@+id/list_myContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" 
     > 
    </ListView> 

</android.support.v4.widget.NestedScrollView> 
+4

das hat bei mir nicht funktioniert. –

+15

Hat nicht auch für mich gearbeitet. Der ListView-Inhalt kann nicht gescrollt werden. –

+6

android: fillViewport = "true" hat die Magie +1 –

27

auf Lollipop ab können Sie

setNestedScrollingEnabled(true); 

auf Ihrem Listview/Gridview/ScrollableView verwenden. Aus der Dokumentation

Aktivieren oder verschachtelte Scrollen für dieses

Ansicht deaktivieren, wenn Sie Rückwärtskompatibilität mit älteren Version des Betriebssystems benötigen Sie die RecyclerView verwenden. Sie können mehr lesen here

Edit. ViewCompat hat die statische Methode setNestedScrollingEnabled(View, boolean). Z.B.

ViewCompat.setNestedScrollingEnabled(listView, true) 

dank @Dogcat es für den Hinweis auf

+1

Diese Antwort sollte definitiv upvoted und sogar als die richtige Antwort jetzt eingestellt werden. Ich änderte schließlich meine Implementierung zu einem 'RecyclerView', weil ich nur die Antwort las, die als die Antwort angenommen wurde. Ja, natürlich hätte ich alle Antworten lesen können, aber der erste funktionierte für mich - wenn es nur ein Aufwand war, die Implementierung zu ändern ;-) – Darwind

+0

@Dogcat danke für den Zeiger – Blackbelt

+1

Du hast mich gerade gerettet! Und ja, das sollte die akzeptierte Antwort sein – liltof

10

Einfach android:fillViewport="true" in dir NestedScrollView Tag

+0

Bitte erklären Sie, wie Ihre Antwort das Problem löst, es wird jedem helfen, Ihre Lösung mit mehr Klarheit zu verstehen und für zukünftige Referenz. – Aziz

+0

@Aziz tatsächlich hatte ich auch vor demselben Problem und es hat funktioniert. Wenn Sie "fillViewport" auf "true" setzen, wird die Höhe des Inhalts an die Grenzen des Darstellungsbereichs angepasst. – Shivam

0

Sie nicht Listenansicht in einem nestedscrollview.Use Recyclerview mit nestedscrollview

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorAccent" 
     android:orientation="horizontal"> 

     <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/profile_image" 
      android:layout_width="76dp" 
      android:layout_height="76dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="24dp" 
      android:layout_marginStart="24dp" 
      android:src="@drawable/profile" 
      app:border_color="#FF000000" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_marginLeft="20dp" 
      android:layout_toRightOf="@+id/profile_image" 
      android:gravity="center_vertical" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="IRFAN QURESHI" 
       android:textSize="20sp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="[email protected]" /> 
     </LinearLayout> 

     <ImageView 
      android:layout_marginLeft="50dp" 
      android:layout_gravity="center_vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_delete_black" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 

     android:background="@color/colorPrimary" 
     android:gravity="center_horizontal" 
     android:padding="30dp"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:background="@drawable/login_email_bg_round_rect_shape" 
      android:gravity="center_horizontal" 
      android:padding="10dp" 
      android:text="POST A QUERY" /> 
    </LinearLayout> 

     <!--<ListView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
     </ListView>--> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" /> 


    <RelativeLayout 
     android:background="@color/colorAccent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:padding="8dp" 
      android:gravity="center_vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="SIGN OUT" /> 
     <ImageView 
      android:paddingTop="5dp" 
      android:layout_marginRight="40dp" 
      android:layout_alignParentRight="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_delete_black" /> 
    </RelativeLayout> 
</LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

</android.support.v4.widget.NestedScrollView> 
0

blättern Fügen Sie einfach android: nestedScrollingEnabled = "true" -Tag in Ihre NestedScrollView ein.

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="none" 
    android:nestedScrollingEnabled="true"> 
    <ListView 
     android:id="@+id/list_myContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical"> 
    </ListView> 

+1

Dieser Wert wird nur in API 21 und höher unterstützt. Leider baue ich für mindestens 16. –

0

das ist, was für mich gearbeitet.

gesetzt android:fillViewport="true" auf die NestedScrollView

Ein Layout-Element als Kind zu NestedScrollView hinzufügen.In meinem Fall LinearLayout und setzen android:nestedScrollingEnabled="true" auf ListView ListView Machen Sie ein Kind von LinearLayout

Gut

0

zu gehen Below-Code für mich gearbeitet:

ViewCompat.setNestedScrollingEnabled (Listview, true);

Ihre Listenansicht innen NestedScrollView sein sollte