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
Antwort
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.
können Sie es beheben, wenn Sie addtribute
android: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>
das hat bei mir nicht funktioniert. –
Hat nicht auch für mich gearbeitet. Der ListView-Inhalt kann nicht gescrollt werden. –
android: fillViewport = "true" hat die Magie +1 –
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
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
@Dogcat danke für den Zeiger – Blackbelt
Du hast mich gerade gerettet! Und ja, das sollte die akzeptierte Antwort sein – liltof
Einfach android:fillViewport="true"
in dir NestedScrollView
Tag
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
@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
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>
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>
Dieser Wert wird nur in API 21 und höher unterstützt. Leider baue ich für mindestens 16. –
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
zu gehen Below-Code für mich gearbeitet:
ViewCompat.setNestedScrollingEnabled (Listview, true);
Ihre Listenansicht innen NestedScrollView sein sollte
http://stackoverflow.com/a/6211286 – Sree