Ich habe eine Navigationsansicht erstellt, in der eine dynamische Liste zur Laufzeit aus den vom Server abgerufenen Daten erstellt wird. Es funktioniert gut und zeigt die Liste an, sobald eine erfolgreiche Kommunikation mit dem Server stattgefunden hat. Das Problem ist, dass ich keine Elemente wie Einstellungen und Über uns am Ende der Liste hinzufügen kann. Das folgende Layout (activity_main.xml) führt in den Menüpunkten überschattend die Listenansicht Artikel:So verwenden Sie Menü und ListView gleichzeitig in einer Navigationsansicht
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:elevation="@dimen/padding"
app:menu="@menu/navigation_items"
>
<android.support.v7.widget.ListViewCompat
android:id="@+id/categories_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_gravity="center"
android:layout_marginStart="@dimen/margin_side"
android:layout_marginLeft="@dimen/margin_side"
android:layout_marginTop="@dimen/nav_header_height"
android:layout_marginBottom="48dp"
/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Und dies ist der Inhalt des navigation_items.xml (Menüressource):
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/nav_bottom"
android:orderInCategory="0">
<item
android:id="@+id/settings"
android:icon="@drawable/settings"
android:title="@string/settings" />
<item
android:id="@+id/about_us"
android:icon="@drawable/info"
android:title="@string/about_us" />
</group>
</menu>
Das Ergebnis auf Emulator wie folgt:
können Sie keine Menüelemente in der Liste hinzufügen, anstatt "app: menu =" @ menu/navigation_items "'. Wie listview mit Standard-Elementen und wenn Sie neue Elemente haben, zeigen Sie sie mit listview – Raghunandan
Können Sie bitte Ihren Java-Code posten. –
@Raghunandan nein, ich muss die Liste im laufenden Betrieb erstellen. – JasonStack