2017-06-28 138 views
0

Bugged titleCollapsingToolbarLayout顯示倒塌

時嘿,你可以在這個圖片中看到破碎的標題,我試圖用CollpasingToolbarLayout但標題沒有被正確繪製。在展開狀態下,我將標題設置爲淡出,如下所示:

val collapsingToolbarLayout = layout.findViewById<CollapsingToolbarLayout>(R.id.collapsing_toolbar) 
    collapsingToolbarLayout.setExpandedTitleColor(android.R.color.transparent) 

所以展開狀態並不重要。我的xml看起來像這樣:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:fitsSystemWindows="true" 
     app:expanded="false" 
     > 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginStart="48dp" 
      app:expandedTitleMarginEnd="64dp" 
      android:fitsSystemWindows="true"> 

      <CalendarView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingBottom="35dp"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       app:title="Title" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_collapseMode="pin"> 

      </android.support.v7.widget.Toolbar> 

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

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

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <include layout="@layout/main_fragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

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

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

Whan can I try?我想這是一個錯誤,但我不知道。謝謝

回答

1

android:fitsSystemWindows="true"通常會在某些情況下添加適當的填充以確保視圖不會在狀態欄/導航欄下分層。就你而言,我認爲這是推動你的文本向下的原因。

您可能需要玩這個,但嘗試將其移除您的AppBarLayout及其子項,也許嘗試一些不同的組合。

它也可能有助於向我們展示視圖邊界,以便我們可以看到視圖的實際位置。這可以在Android Studio預覽版或通過開發者選項完成