2012-02-13 150 views
4

我正在創建使用選項卡布局的應用程序。應用程序的要求是應該有很多標籤。在選項卡上製作4-5個選項卡是可以的。但是,當添加更多tham 5個選項卡時,它會變得非常壓縮。有沒有在Android的方式,我可以有很多選項卡,而不是讓它看起來壓縮?也許有些人喜歡在選項卡上有一個「更多」按鈕或有水平滾動選項卡?帶有多個選項卡的Android選項卡布局

我忘了提這個早些時候在Android 2.2(API 8),它應該工作

感謝

+1

爲什麼不在你的標籤中引入水平滾動? – waqaslam 2012-02-13 14:19:37

+0

得到了類似的應用程序,但我擺脫了標籤,只是添加箭頭左/右之間的標題。 – goodm 2012-02-13 14:23:13

+2

水平滾動標籤可以是推薦的方法。查看http://developer.android.com/design/patterns/app-structure.html和「類別」部分 – Jave 2012-02-13 14:24:56

回答

2

對於標籤佈局的行

app:tabMode="scrollable" 

添加到您的XML文件,例如

<android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:tabMode="scrollable" 
     app:tabTextColor="@color/colorWhite" 
     app:tabSelectedTextColor="@color/colorSecondary" 
     android:background="@color/colorPrimary" 
     app:tabIndicatorColor="@color/colorSecondary" 
     app:tabIndicatorHeight="5dp"/> 
</android.support.design.widget.AppBarLayout>