2014-03-26 227 views
0

我在我的應用程序中完成了Navigation Drawer,並且工作正常。但我試圖在上面放置另一個Listview,但我無法在屏幕上顯示新的顯示。我已將Navigation Drawer列入BaseActivity類。什麼可能是錯誤?這是我的代碼:Android:2瀏覽器中的瀏覽器

XML

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

<LinearLayout 
... 

</LinearLayout> 


<LinearLayout android:layout_width="250dp" 
    android:layout_height="match_parent" 

    android:layout_gravity="start" 
    android:orientation="vertical"> 


<ListView 
    android:id="@+id/listview_drawer" 
    style="@style/scrollbar" 
    android:layout_width="250dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@color/grisTransparente" 
    android:choiceMode="singleChoice" 
    android:divider="@color/negro" 
    android:dividerHeight="1dp" /> 


<ListView 
    android:id="@+id/listview_drawer2" 
    android:layout_width="250dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="@color/negro" 
    android:dividerHeight="1dp" 
    android:background="@color/grisTransparente" 
    style="@style/scrollbar"/> 
</LinearLayout> 


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

BASEACTIVITY

private void cargarDrawerLayout(Bundle b) { 

    mTitle = mDrawerTitle = getTitle(); 

    textosMenuLateral = getResources().getStringArray(R.array.titulos_drawer); 
    textosMenuLateral2 = getResources().getStringArray(R.array.titulos_drawer2); 

    iconosMenuLateral = getResources() 
      .obtainTypedArray(R.array.iconos_drawer); 

    iconosMenuLateral2 = getResources() 
      .obtainTypedArray(R.array.iconos_drawer2); 

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 

    mDrawerList = (ListView) findViewById(R.id.listview_drawer); 
    mDrawerList2 = (ListView) findViewById(R.id.listview_drawer2); 

    View header = getLayoutInflater().inflate(R.layout.drawer_header, null); 
    mDrawerList.addHeaderView(header); 
    mDrawerList2.addHeaderView(header); 

    int[] colores = {0, 0xFFFFFFFF, 0}; 
    mDrawerList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colores)); 
    mDrawerList.setDividerHeight(4); 

    mDrawerList2.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colores)); 
    mDrawerList2.setDividerHeight(4); 

    navDrawerItems = new ArrayList<DrawerItem>(); 
    navDrawerItems2 = new ArrayList<DrawerItem>(); 

    navDrawerItems.add(new DrawerItem(textosMenuLateral[0], iconosMenuLateral.getResourceId(0, -1))); 
    navDrawerItems.add(new DrawerItem(textosMenuLateral[1], iconosMenuLateral.getResourceId(1, -1))); 
    navDrawerItems.add(new DrawerItem(textosMenuLateral[2], iconosMenuLateral.getResourceId(2, -1))); 

    navDrawerItems2.add(new DrawerItem(textosMenuLateral2[0], iconosMenuLateral2.getResourceId(0, -1))); 

    iconosMenuLateral.recycle(); 
    iconosMenuLateral2.recycle(); 

    mDrawerList.setOnItemClickListener(new SlideMenuClickListener()); 
    mDrawerList2.setOnItemClickListener(new SlideMenuClickListener2()); 

    adapter = new DrawerListAdapter(getApplicationContext(), 
      navDrawerItems, 
      perfilObj.getColor(), 
      pos); 
    mDrawerList.setAdapter(adapter); 

    adapter2 = new DrawerListAdapter(getApplicationContext(), 
      navDrawerItems2, 
      perfilObj.getColor(), 
      pos2); 
    mDrawerList2.setAdapter(adapter2); 

    mDrawerToggle = new ActionBarDrawerToggle(
      this, 
      mDrawerLayout, 
      R.drawable.icono_drawer, 
      R.string.app_name, 
      R.string.app_name 
    ) { 
     public void onDrawerClosed(View view) { 

      getActionBar().setTitle(mTitle); 
      invalidateOptionsMenu(); 
     } 

     public void onDrawerOpened(View drawerView) { 

      getActionBar().setTitle(mDrawerTitle); 

      invalidateOptionsMenu(); 
     } 
    }; 
    mDrawerLayout.setDrawerListener(mDrawerToggle); 
} 

private class SlideMenuClickListener implements ListView.OnItemClickListener { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 

     TextView textView = (TextView) view.findViewById(R.id.title); 
     textView.setTypeface(null, Typeface.BOLD);  

     opcionesPanelLateral(position); 
    } 
} 

private class SlideMenuClickListener2 implements ListView.OnItemClickListener { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 

     TextView textView = (TextView) view.findViewById(R.id.title); 
     textView.setTypeface(null, Typeface.BOLD);  

     opcionesPanelLateral2(position); 
    } 
} 

private void opcionesPanelLateral(int position) { 

    Intent i; 

    switch (position - 1) { 
     case 0: 


     case 1: 


     case 2: 


     case 3: 

      break; 

     default: 
      break; 
    } 

    mDrawerList.setItemChecked(pos, true); 
    mDrawerList.setSelection(pos); 
     setTitle(textosMenuLateral[pos]); 

    mDrawerLayout.closeDrawer(mDrawerList); 
} 

private void opcionesPanelLateral2(int position) { 

    Intent i; 

    switch (position) { 
     case 0: 
      break; 

     default: 
      break; 
    } 

    mDrawerList2.setItemChecked(pos, true); 
    mDrawerList2.setSelection(pos); 

    mDrawerLayout.closeDrawer(mDrawerList2); 
} 
+0

爲什麼你想在第一個地方有2個listviews?難道你不能自己定製一個適合你需要的內容嗎? –

+0

我想你想要在一個佈局和抽屜裏顯示兩個列表視圖 –

+0

,因爲我認爲這是獲取標題的最簡單的方法 – Charlie

回答

1

你有沒有嘗試添加布局權重的列表視圖? ListView自然會匹配父級的大小。 Layout Weight我希望它有幫助。

<ListView 
android:id="@+id/listview_drawer" 
style="@style/scrollbar" 
android:layout_width="250dp" 
android:layout_height="match_parent" 
android:layout_gravity="start" 
android:background="@color/grisTransparente" 
android:choiceMode="singleChoice" 
android:divider="@color/negro" 
android:dividerHeight="1dp" 
android:layout_weight="1"/> 

<ListView 
android:id="@+id/listview_drawer2" 
android:layout_width="250dp" 
android:layout_height="match_parent" 
android:layout_gravity="start" 
android:choiceMode="singleChoice" 
android:divider="@color/negro" 
android:dividerHeight="1dp" 
android:background="@color/grisTransparente" 
style="@style/scrollbar" 
android:layout_weight="1"/> 
+0

非常感謝!我的問題解決了 – Charlie