2017-07-18 2 views
0

Ich habe Layoutprobleme in meinem NavigationView. Das Ziel besteht darin, einen Header und eine Listenansicht mit einem Adapter bereitzustellen. Zuerst musste ich diesen Code:ListView in LinearLayout nicht sichtbar

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/lib/com.plaxxt.plaxxt1" 
    android:paddingLeft="0dp" 
    android:paddingRight="0dp" 
    android:paddingTop="0dp" 
    android:paddingBottom="0dp" 
    tools:context=".MainActivity" 
    android:id="@+id/drawerLayout" 
    android:fitsSystemWindows="true"> 

    <RelativeLayout 
     android:layout_width = "match_parent" 
     android:layout_height = "match_parent"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/my_awesome_toolbar" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:minHeight="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" /> 


     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="?attr/actionBarSize"> 
(...) 
      </FrameLayout> 
    </RelativeLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true"> 

     <android.support.v4.widget.NestedScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="start"> 

       <include layout="@layout/drawer_header" /> 

       <ListView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/lst_menu_items" /> 

      </LinearLayout> 

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

    </android.support.design.widget.NavigationView> 

</android.support.v4.widget.DrawerLayout> 

und diese Ergebnisse wie folgt aus (Header gibt es keine Liste)

enter image description here

Wenn ich den Header mit einem Dummy-Bild ersetzen, beide erscheinen, obwohl :

<android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true"> 

     <android.support.v4.widget.NestedScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="start"> 

       <ImageView 
        android:id="@+id/imageView" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="@dimen/nav_header_vertical_spacing" 
        android:src="@android:drawable/sym_def_app_icon" /> 

       <ListView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/lst_menu_items" /> 

      </LinearLayout> 

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

    </android.support.design.widget.NavigationView> 

Das Ergebnis ist:

enter image description here

So sehen wir, dass die Liste korrekt mit meinem Adapter generiert wird.

Wenn ich das Bild entfernen und die ListView als einziges Kind der LinearLayout lassen, bleibt die Schublade leer.

Wo ist der Fehler? Bitte helfen Sie mir ...

+0

Fabrikat 'NestedScrollView' Höhe' match_parent', Linearlayout 'wrap_content' und Listview' wrap_content' – Piyush

+0

@Piyush sorry, keine Wirkung ... –

+0

Ich empfehle auch 'RecyclerView' anstelle von' ListView' zu verwenden. – Piyush

Antwort

1

Versuchen Sie, Orientierung an den Linearlayout

<LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="start" 
       android:orientation="vertical"> 

       <ImageView 
        android:id="@+id/imageView" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="@dimen/nav_header_vertical_spacing" 
        android:src="@android:drawable/sym_def_app_icon" /> 

       <ListView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/lst_menu_items" /> 

      </LinearLayout> 
Verwandte Themen