2013-12-11 103 views
0

我有一個Navigation Drawer問題。
在我的導航抽屜應用程序中,有時抽屜會顯示在其他內容視圖的後面。所以只顯示抽屜的一部分(其他部分被內容區域隱藏)。Android導航抽屜(DrawerLayout)被內容視圖隱藏

我嘗試了一切,但它不起作用。

drawer.bringToFront(); 
    drawer.buildLayer(); 
    drawer.clearFocus(); 
    drawer.requestLayout(); 
    drawer.forceLayout(); 

但是在這種情況下,如果我觸摸選項按鈕或改變焦點,屏幕刷新並且它很好地顯示抽屜。 所以我想知道什麼樣的方法被稱爲當我觸摸選項按鈕。然後,我想我可以在抽屜打開時調用該方法。

非常感謝你的高級。

+0

發佈包含主要內容視圖和導航抽屜的佈局XML文件。 – Squonk

+0

@Squonk,對不起。我無法上傳XML,該應用程序已商業化幷包含許多視圖:( – nayeong

+0

除非您發佈相關代碼/佈局文件以重現該問題,否則沒有人能夠爲您提供幫助。 – Squonk

回答

0

我張貼示例代碼嘗試檢查您的代碼。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <RelativeLayout 
     android:id="@+id/relative_home" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/tile_image_data" > 


     <android.support.v4.view.ViewPager 
      android:id="@+id/viewpager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="48dip" > 
     </android.support.v4.view.ViewPager> 
    </RelativeLayout> 

    <ListView 
     android:id="@+id/drawer" 
     android:layout_width="240dp" 
     android:layout_height="fill_parent" 
     android:layout_gravity="right" 
     android:cacheColorHint="#00000000" 
     android:divider="#19000000" 
     android:background="@drawable/tile_image_data" 
     android:choiceMode="singleChoice" /> 

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

我有同樣的問題。我通過將android:id中的FrameLayout@android:id/content更改爲@+id/content來解決問題。顯然,使用系統資源ID並不總是一個好主意。

0

我有同樣的問題。當主視圖調用onWindowsFocusChange()時,抽屜在主視圖後面打開。這發生在Unity3D視圖中。 我已經解決了函數 onDrawerSlide(View drawerView, float slideOffset) 中調用的問題,它是DrawerListener,drawerView.bringToFront()中的一個方法。

0

我有同樣的問題,但它似乎只發生在KITKAT之前的版本。由於@jack,我更新的代碼之後後,它是確定:

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, 
      R.string.drawer_close) { 
     @Override 
     public void onDrawerSlide(View drawerView, float slideOffset) { 
      super.onDrawerSlide(drawerView, slideOffset); 

      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 
       drawerView.bringToFront(); 
       getWindow().getDecorView().requestLayout(); 
       getWindow().getDecorView().invalidate(); 
      } 
     } 
    }; 

你可能想知道爲什麼我調用requestLayout()和無效(),只是看到bringToFront的文檔()。