2017-02-15 44 views
0

我的AppBar做奇怪的事情。 這就是它在720x1280屏幕上的樣子: enter image description hereAppBar錯誤的高度

這就是它應該看起來的樣子。這是它在1080x1920屏幕上的樣子: enter image description here 我在app_bar_main.xml中玩弄了工具欄高度,但我不喜歡它,所以我將其設置回默認的?attr/actionBarSize值。可能是什麼問題呢?這裏是我的app_bar_main.xml:

<?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.koostamas.justtry.MainActivity"> 

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

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

這裏是我的activity_main.xml中:

<?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="match_parent" 
android:orientation="vertical" > 

<include 
    android:id="@+id/app_bar" 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/containerView"> 
    </FrameLayout> 


    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:id="@+id/drawerPane" 
     android:layout_gravity="start"> 

     <!-- List of Actions (pages) --> 
     <ListView 
      android:id="@+id/navList" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:choiceMode="singleChoice" 
      android:background="@color/busblue"/> 

    </RelativeLayout> 

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

</LinearLayout> 
+0

從取出的高度和寬度屬性的包括佈局代碼 –

+0

這解決了高度,但然後導航抽屜和appbar下面的片段消失,只有白色背景可見。 –

回答

1

嘗試更新你的代碼。就我而言,這個問題與你的觀點有關。你的方法是不正確的。如果您只包含工具欄,那麼需要coordinateLayoutAppBarLayout

更新app_bar_main.xml OCDE本

<?xml version="1.0" encoding="utf-8"?> 
<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" /> 

更新您的activity_main.xml代碼與此

<?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="match_parent" 
    android:orientation="vertical"> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include 
     android:id="@+id/app_bar" 
     layout="@layout/app_bar_main" /> 

    <FrameLayout 
     android:id="@+id/containerView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"></FrameLayout> 

    <RelativeLayout 
     android:id="@+id/drawerPane" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start"> 

     <!-- List of Actions (pages) --> 
     <ListView 
      android:id="@+id/navList" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="@color/busblue" 
      android:choiceMode="singleChoice" /> 

    </RelativeLayout> 

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

+0

如果我將它包含在內,就像你說appbar位於它下面的片段後面,並且如果我將drawerlayout外部的include包括在內(因爲我希望導航抽屜在我的appbar下面開始),那麼它看起來與之前一樣。 –

+0

好吧,我會更新一個XML,做一件事情排除這些上述XML和結論,只有一個 –

+0

我明白了。你發佈的xml文件是不正確的,但你寫道,我不需要CoordinatorLayout,你是對的。這解決了它。謝謝。請更新帖子,如果有其他人需要答案,這將是明確的。 –