2016-04-27 57 views
2

我嘗試使用ListView將自定義Navigation Drawer添加到Activity。 在我添加Navigation Drawer之前,可以滾動ListView並選擇項目,但是當我添加抽屜時,它不再執行此操作。 當我在Navigation Drawer之上添加ListView時,Navigation Drawer有效。 但是,當我把它ListView下,Navigation Drawer不起作用。Android:當添加抽屜時ListView不會滾動

<?xml version="1.0" encoding="utf-8"?> 
<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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.theoryx.androidapp.Search"> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/snackbarPosition"> 
    </android.support.design.widget.CoordinatorLayout> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

//<include layout="@layout/content_my_library" /> //<----here 

    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ListView 
      android:id="@+id/navList" 
      android:layout_width="200dp" 
      android:layout_marginTop="55dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="left|start" 
      android:background="#ffffff"/> 
    </android.support.v4.widget.DrawerLayout> 

    <include layout="@layout/content_my_library" /> //when I put this above it the drawer works but then the listview doesn't scroll and cant be selected. 

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

Content_my_library:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="0dp" 
    android:background="@color/white" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.theoryx.androidapp.MyLibrary" 
    tools:showIn="@layout/activity_my_library"> 

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

</RelativeLayout> 

回答

1

,如果你想使用的導航抽屜充分利用DrawerLayout根元素。

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.CoordinatorLayout> 
     <!-- All the things. --> 
    </android.support.design.widget.CoordinatorLayout> 

    <ListView 
     android:id="@+id/navList"/> 

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

該代碼與問題中完全相同,單獨意味着什麼。添加更多來展示你的想法。 –

+0

基本上抽屜佈局必須是根元素,只是剪斷我不知道他想如何佈局佈局 – Haroon

+0

***我得到你的意思。但我沒有問這個問題。請下次更詳細。 –