1

我是新的CoordinatorLayout我想在我的應用程序中使用coordinatorLayout,但它在顯示CollapsingToolbarLayout視圖時會導致一些問題。CoordinatorLayout與Android中的選項卡?

enter image description here

我想設計視圖例如WhatsApp屏幕TabsCoordinatorlayout

我的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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/detail_backdrop_height" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 


     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="false" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="32dp" 
      app:expandedTitleMarginStart="24dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 


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

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

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

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabanim_tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

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


    <android.support.v4.view.ViewPager 
     android:id="@+id/tabanim_viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

     // child view 

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

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

回答

8

我CoordinatorLayout

找到解決方案選項卡
<?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" 
    android:id="@+id/tabanim_maincontent" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/tabanim_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/tabanim_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

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

     /*** 
        Here You can add custom layout 
       **/ 


     <android.support.design.widget.TabLayout 
      android:id="@+id/tabanim_tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/tabanim_viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 


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

「,但它是原因e顯示器出現問題「沒有說出你遇到了什麼樣的問題,很高興你找到了解決方案。

在使用fitsSystemWindows =「true」的同時,在CoordinatorLayout中,使用TabLayout和ViewPager的22.2.1和23.0.1支持庫確實存在問題。在使用RecyclerView並向上滾動時,TabLayout標題進入狀態欄,而其背景顏色未被固定。

我可能只意味着上面是你的問題之一,如果是,那麼除去fitsSystemWindows並不像申請將失去很多它的外觀在5.0以上的Android最好的解決方案。

這不是好的解決方案,但我設法通過加入嵌套android.support.design.widget.CoordinatorLayout來解決這個問題,但如果你使用DrawerLayout存在,則需要毫無作爲本例所示:https://github.com/chrisbanes/cheesesquare