0

我想在同一個主要活動中有2個listview。我的水平抽屜的一個列表視圖(從左邊滑動)和另一箇中心的列表視圖。當我點擊抽屜時,它會顯示抽屜列表視圖,但抽屜視圖不會滑過中心列表視圖,而是中心位於其上,所以我實際上看不到抽屜裏的任何東西。我想知道,如果有什麼問題我main_activity.xml我RES /佈局目錄(其實我不知道它是做它把一個活動的兩個列表視圖以正確的方式)在抽屜頂部的ListView ListView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       tools:context=".MainActivity" > 

      <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/drawer" 
          android:layout_width="240dp" 
          android:layout_height="match_parent" 
          android:layout_gravity="start" 
          android:choiceMode="singleChoice" 
          android:divider="@android:color/transparent" 
          android:dividerHeight="0dp" 
          android:background="#111"/> 

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

      <ListView android:id="@+id/deviceList" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:divider="#b5b5b5" 
         android:dividerHeight="1dp" 
         android:listSelector="@drawable/list_selector" /> 

</RelativeLayout> 
+1

你能提供你的屏幕截圖嗎?我認爲一個圖像比許多單詞講得更多。 – R4j

回答

1

我想你可以簡單地通過具有這樣

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

    <ListView 
     android:id="@+id/deviceList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#b5b5b5" 
     android:dividerHeight="1dp" 
     android:drawSelectorOnTop="false" 
     android:listSelector="@drawable/device_list_item_selector" 
     android:scrollbarStyle="outsideOverlay" /> 
</LinearLayout> 

<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="fill_parent" > 

    <ListView 
     android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="#111" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" /> 
</android.support.v4.widget.DrawerLayout> 

的DrawerLayout之前ListView控件(與LinearLayout中把它包)重新排序,並確保你已經爲FILL_PARENT爲layout_height既

1

試試這個: -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relative" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. --> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <!-- 
     As the main content view, the view below consumes the entire 
     space available using match_parent in both dimensions. 
     --> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/view_pager" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" /> 

     <RelativeLayout 
      android:id="@+id/relative1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <ListView 
       android:id="@+id/lst_week" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:dividerHeight="1dp" > 
      </ListView> 
     </RelativeLayout> 

     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <ListView 
      android:id="@+id/left_drawer" 
      android:layout_width="300dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:choiceMode="singleChoice" 
      android:dividerHeight="0.5dp" /> 
    </android.support.v4.widget.DrawerLayout> 

</RelativeLayout>