2016-11-30 73 views
0

樣品的Gif:enter image description here如何使移動動畫TabLayout

我要讓TabLayout移動動畫效果相同樣本GIF。在此示例中,TabLayout包含兩個選項卡(收入,費用)。在右側或左側滑動它會改變它們的背景顏色。我怎樣才能做到這一點。

我已成功使ViewPager與TabLayout。我不知道做這種類型的動畫。請幫助。

TabLayout:

<android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" 
     app:tabIndicatorColor="@color/white" 
     app:tabBackground="@color/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 
+0

我會說你不需要TabLayout來實現這種效果。也許一個切換按鈕,並沒有左/右滑動會做的伎倆。 – user3641702

+0

這樣的例子嗎? – Zohaib

回答

0

這是一個相當大的問題,但我建議你先創建選項卡中的自定​​義視圖。請參閱Tab.setCustomView()

其次,您應該處理動畫,可能使用viewPager的滾動偏移量。 ViewPager.OnPageChangeListener.html#onPageScrolled(int, float, int)

您將要使用positionOffset更新選擇器的位置和顏色。

希望這會給你一個指導如何做到這一點。

+0

這樣的例子嗎? – Zohaib

+0

我有解決方案的一部分。填充TabLaout的高度時增加tabIndicator的高度。由此我們可以實現轉換效果,但問題是TabLayout的文本變得不可見。我不知道如何使它可見。 – Zohaib

+0

你說我的解決方案? – Zohaib