2016-02-04 31 views
2

我正在玩新的Transition Api,並希望在兩個活動之間實現良好的轉換。這兩項活動都包含帶有標籤ViewPagerAppBarAndroid活動轉換 - Window.excludeTarget()阻止子視圖的轉換

當我運行過渡的第一個時代,AppBar也逐漸消失了,並再次在兩個活動轉換之間,所以它看上去就像是閃爍:

enter image description here enter image description here

爲了解決這個我試圖通過調用transition.excludeTarget()排除從活動過渡AppBar

// in onCreate() of the calling activity 
Transition transition = new Fade(); 
transition.excludeTarget(mAppBarLayout, true); 
getWindow().setExitTransition(transition); 
getWindow().setReenterTransition(transition); 

// in onCreate() of the called activity 
Transition transition = new Fade(); 
transition.excludeTarget(mAppBarLayout, true); 
getWindow().setEnterTransition(transition); 
getWindow().setReturnTransition(transition); 

這代碼解決了閃爍的問題,但引入了一個新問題:有沒有交叉淡化動畫爲ViewPager Tabs了:

enter image description here

這兩種佈局看怎麼樣在generell:

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:background="@color/toolbar_background" 
     > 
     <android.support.v7.widget.Toolbar 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:titleTextColor="@color/toolbar_icons" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/Base.ThemeOverlay.AppCompat.Dark" 
      /> 
     <com.ogaclejapan.smarttablayout.SmartTabLayoutLight 
      android:layout_width="match_parent" 
      android:layout_height="48dp" 
      /> 
    </android.support.design.widget.AppBarLayout> 
    <android.support.v4.view.ViewPager 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    /> 
</android.support.design.widget.CoordinatorLayout> 

是否有一個從過渡動畫中排除視圖/佈局,但包含其子項的方法?我試圖通過調用transition.addTarget(mTabs);來添加ViewPager Tabs,但它沒有什麼區別。

回答

0

你應該只排除你的工具欄,而不是整個AppBarLayout。

transition.excludeTarget(toolbar, true);