2014-12-03 17 views
1

我正在使用此庫https://github.com/astuetz/PagerSlidingTabStrip來創建PagerTabStrip。PagerTabStrip - 將選項卡居中或使它們適合

我的輸出enter image description here

你可以看到,我的標籤後,我有一些空的空間。 我想使標籤適合所有屏幕,或至少居中標籤。 這可能嗎?

<com.astuetz.PagerSlidingTabStrip 
     android:layout_gravity="center_horizontal" 
     android:gravity="center_horizontal" 
     android:background="@color/facebook_theme_light" 
     android:id="@+id/activity_posts_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="48dip" /> 

    <android.support.v4.view.ViewPager 
     android:background="@color/facebook_theme_dark" 
     android:id="@+id/activity_posts_pager" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/activity_posts_tabs" 
     tools:context=".MainActivity" /> 

回答

6

去尋找一個解決方案,並有一個內置在庫,只需使用:

psts:pstsShouldExpand="true" 

並且選項卡將在佈局中展開並居中。

+0

是的,這是一個很好的解決方案:) – 2015-04-19 19:40:58

1

這應該是一個評論,但是當我試圖把它在評論的形式,它看起來反常,所以在這裏你去:

如果你去the sample xml for the library you provided

你會發現,在XML有看法 -

<com.astuetz.PagerSlidingTabStrip 
    android:id="@+id/tabs" 
    android:layout_width="match_parent" 
    android:layout_height="62dip" 
    android:layout_below="@+id/image" 
    android:background="@drawable/background_tabs_diagonal" 
    app:pstsDividerColor="#00000000" 
    app:pstsIndicatorColor="#FF33B5E6" 
    app:pstsTabPaddingLeftRight="14dip" 
    app:pstsUnderlineColor="#FF33B5E6" /> 

這有一個寬度"match_parent"。你需要做的是在你的應用程序中將這個相當於"wrap_content"改爲android:layout_gravity="center_horizontal" ....或者沿着這些行添加一些東西,因爲我沒有測試過它。

編輯

您也可以嘗試它包裹在一個容器

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <com.astuetz.PagerSlidingTabStrip 
     android:id="@+id/tabs" 
     android:layout_width="wrap_content" 
     android:layout_height="62dip" 
     android:layout_below="@+id/image" 
     android:layout_centerInParent="true" 
     android:background="@drawable/background_tabs_diagonal" 
     app:pstsDividerColor="#00000000" 
     app:pstsIndicatorColor="#FF33B5E6" 
     app:pstsTabPaddingLeftRight="14dip" 
     app:pstsUnderlineColor="#FF33B5E6" /> 

</RelativeLayout> 
+0

因爲我使用的是相對佈局,所以我沒有包裝內容,而android:layout_centerHorizo​​ntal =「true」 用於我的pagertabstrip。結果是這個http://i.snag.gy/MHjEK.jpg ...是居中的,但我需要使它適合佈局內部...而不是在側邊的間隙,也可以使它們像等於合適? – 2014-12-03 20:59:47

+0

@Paul所以你希望他們跨越整個佈局均勻跨度?您可能必須提供一個自定義視圖來處理您的測量事項,但是當我抽出一點時間時,我會查看一些事情,看看是否沒有選項提供幫助。 – zgc7009 2014-12-03 21:01:39

+0

我想這正是我想要的http://i.snag.gy/svulG.jpg。我希望可以用這個庫 – 2014-12-03 21:02:53

相關問題