2016-02-29 68 views
0

我在ViewPager中使用庫PagerSlidingTabStrip動態數量的標題。這是一個很棒的圖書館,易於使用,但我需要更多地定製它。PagerSlidingTabStrip選定的選項卡行頂部

我的PagerSlidingTabStrip標題位於屏幕的底部,因此,我需要在PagerSlidingTabStrip組件的頂部顯示'全寬下劃線'和'選中的項目行指示符'。

一些測試後,我在正確的位置,終於在「全寬下劃線」,使用附配的LinearLayout是這樣的:

<LinearLayout 
     android:id="@+id/tabs_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentBottom="true"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:orientation="vertical" 
      android:background="@color/lfp_yellow"/> 

     <com.astuetz.PagerSlidingTabStrip 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="48dip" 
      app:pstsDividerColor="@android:color/transparent" 
      app:pstsIndicatorColor="@color/light_yellow" 
      app:pstsIndicatorHeight="4px" 
      app:pstsShouldExpand="true"/> 
    </LinearLayout> 

但我還沒有形成的地方「所選項目線指示」處最佳。我試圖改變所選項目的背景,與頂部的線繪製,但不工作:(

任何想法?

非常感謝。

回答

0

最後我找到了解決方案,但它需要。一些變化庫代碼

首先,我們需要在我們的項目中,沒有外部的依賴作爲通常添加庫代碼:

dependencies { 
compile 'com.jakewharton:butterknife:6.0.0' 
} 

佛r,在我們的Android Studio項目中有一個非常有用的導入庫項目的教程。而且,在本教程中,它將使用此PagerSlidingTabStrip庫作爲示例! (完美!)

How do I add a library project to Android Studio?

之後,我們只需要打開PagerSlidingTabStrip.java文件,然後轉到 '的onDraw' 功能。

我們必須改變這一行:

canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); 

對於這一個:

canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight , rectPaint); 

它完成!

在另一方面,如果你有興趣在修改這個庫,也許你會找到有用的這個修改過(可能包含在庫的主分支的未來):

https://github.com/astuetz/PagerSlidingTabStrip/pull/62/files?short_path=04c6e90

我希望這會對某人有用:)

相關問題