2016-03-16 131 views
0

我試圖通過ViewPagerTabLayout實現CollaspingToolbarLayout,但我在測試設備上呈現視圖時遇到問題。Android CollaspingToolbarLayout怪癖

no image description

在滾動它的行爲像這樣,示出了標題上方的欄。

no image description

我的佈局看起來像這樣

<?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: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="320dp"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:minHeight="112dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/image" 
       android:src="@drawable/login" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="fitXY" 
       android:fitsSystemWindows="true" 
       app:layout_collapseMode="parallax"/> 

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

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

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

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:background="@color/colorBackground" 
     app:layout_anchor="@+id/app_bar_layout" 
     app:layout_anchorGravity="bottom" 
     app:layout_collapseMode="none"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/movie_tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:background="@color/colorPrimary" 
      app:layout_anchor="@+id/app_bar_layout" 
      app:layout_anchorGravity="bottom" 
      app:layout_collapseMode="none" 
      app:tabGravity="fill" 
      app:tabIndicatorColor="#fff" 
      app:tabIndicatorHeight="2dp" 
      app:tabMode="fixed" 
      app:tabSelectedTextColor="#fff" 
      app:tabTextColor="#fff" /> 

    </FrameLayout> 

    <android.support.v4.view.ViewPager 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:id="@+id/movieviewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="?attr/actionBarSize" /> 

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

我有同樣的問題,我通過給給'安卓固定它:layout_marginTop =「22sp」'工具欄 – Sree

+0

我會嘗試儘快 – MrFoh

+0

@Sree沒有運氣仍然相同 – MrFoh

回答

0

嘗試。

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

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

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


      <android.support.v4.view.ViewPager 
       android:id="@+id/header" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/photo" 
       android:fitsSystemWindows="true" 

       app:layout_collapseMode="parallax" /> 

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

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:layout_gravity="bottom" 
       app:tabIndicatorColor="@color/colorAccent" /> 

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

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

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

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

示例代碼:https://goo.gl/iBimYe