2016-05-14 12 views
4

我使用的是具有可擴展列表視圖的導航視圖。我以編程方式添加頁眉佈局。但它從頂部切斷。如果我給標題佈局高度240dp比看起來好,但在較低的版本,它需要很多高度。繼承人我的標題佈局xml,我膨脹到可擴展列表視圖的標題。導航頁眉佈局從頂部切除

navigation_header

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/colorPrimary" 
       android:gravity="bottom" 
       android:orientation="vertical" 
       android:paddingBottom="@dimen/activity_vertical_margin" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:paddingTop="@dimen/activity_vertical_margin" 
    > 

    <com.lib.CircleImageView 
     android:id="@+id/imageViewHeaderPerson" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:src="@android:drawable/sym_def_app_icon"/> 

    <TextView 
     android:id="@+id/textViewName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:text="Android Studio" 
     android:textAppearance="@style/TextAppearance.AppCompat.Subhead" 
     android:textColor="@color/DEFAULT"/> 

    <TextView 
     android:id="@+id/textViewCode" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="@style/Base.TextAppearance.AppCompat.Body1" 
     android:text="heelo" 
     android:textColor="@color/DEFAULT"/> 

</LinearLayout> 

,並有我的導航佈局抽屜

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

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

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

    </LinearLayout> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     > 
    <ExpandableListView 
     android:groupIndicator="@null" 
     android:id="@+id/left_drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white" 
     android:headerDividersEnabled="false" 
     android:childDivider="#00000000" 


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

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

您在使用layout_below財產 – Manifest

+0

我不使用工具欄把工具欄下方的導航視圖。它是一個行動欄。我正在提供在商工具欄'actionBarDrawerToggle =新ActionBarDrawerToggle空( 此, drawerLayout, 空, navigationConfig.getDrawerOpenDesc(), navigationConfig.getDrawerCloseDesc() )'可你的代碼段爲你在說什麼 –

回答

0

我用這個解決了這個。感謝評論設置下面的toobar導航視圖。

// Calculate ActionBar height 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      TypedValue tv = new TypedValue(); 
      int actionBarHeight = 0; 

      if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { 
       actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources() 
         .getDisplayMetrics()); 
      } 
      ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) expandableListView 
        .getLayoutParams(); 

      mlp.setMargins(0, actionBarHeight, 0, 0); 
      expandableListView.setLayoutParams(mlp); 
     } 
0

添加操作欄大小的頂邊在佈局,像

<ExpandableListView 
    android:groupIndicator="@null" 
    android:id="@+id/left_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:headerDividersEnabled="false" 
    android:layout_marginTop="?attr/actionBarSize" 
    android:childDivider="#00000000" 
    /> 
+0

機器人:layout_marginTop =「?attr/actionBarSize」,但它只支持api 11以上。我正在使用最小8 api級別。你知道這個的替代嗎? –

8

添加您NavigationView android:fitsSystemWindows="false"

+0

這是正確的答案,應該被接受 – blueware