6

我正試圖實現這個應用程序。目前我已經設計了選項卡,因爲我有超過7個選項卡,它看起來過於擁擠。我如何設計它,以便tabwidget可水平滾動。我已經在市場上的幾款應用中看到過這種設計,但不知道如何在我的應用中實現這一點。如何實現水平滾動的標籤?

我看到的一個應用程序有一個水平滾動視圖,它自己滾動,當您按下特定圖像/按鈕時,它會顯示一些內容。它似乎沒有我猜的標籤。

那麼有沒有人有這個想法?

回答

3

請查看Jake Wharton的ViewPager應用程序。這正是你需要的。這是一個圖書館項目,所以你必須將它包含在你的項目中。

JakeWharton/Android-ViewPagerIndicator

+0

嗨卡爾文感謝您的文章它爲我工作。我正在開發平板電腦的應用程序。但標籤不佔用文本的寬度>。希望你明白我的意思是它看起來全部擁塞我可以爲選項卡sot帽子定義一個寬度,它包含完整的文本。例如:如果有一個選項卡顯示「用戶配置文件」,但它只顯示爲「用戶」 – 2012-03-14 15:34:13

+0

@roses_r只是從庫的類TabPageIndicator中刪除onMeasure(int,int)方法。有用。 – alu 2015-10-19 07:32:54

5

這是通過使用Horizo​​ntalScrollView一個很好的例子。 http://java.dzone.com/articles/scrolling-tabs-android

+0

嗨卡爾文感謝您的文章它爲我工作。我正在開發平板電腦的應用程序。但標籤不佔用文本的寬度>。希望你明白我的意思是它看起來全部擁塞我可以爲選項卡sot帽子定義一個寬度,它包含完整的文本。例如:如果有一個標籤顯示「User Profile」,但只顯示爲「User」 – 2012-03-14 15:34:34

0

檢查此鏈接:https://dzone.com/articles/scrolling-tabs-android

包裝你TabWidget用Horizo​​ntalScrollView和標籤集將 能夠擴展超出屏幕的寬度,並且用戶可以拖動 標籤左右要求:

<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"   android:id="@android:id/tabhost"   android:layout_width="fill_parent"   android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"> <HorizontalScrollView android:layout_width="fill_parent"       android:layout_height="wrap_content"       android:fillViewport="true"       android:scrollbars="none">  <TabWidget android:id="@android:id/tabs"     android:layout_width="fill_parent"     android:layout_height="wrap_content"/> </HorizontalScrollView> <FrameLayout android:id="@android:id/tabcontent"     android:layout_width="fill_parent"     android:layout_height="fill_parent" /> </LinearLayout></TabHost> 
12

TabLayout從Android的設計庫

<android.support.design.widget.TabLayout 
    android:id="@+id/categories" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:tabMode="scrollable" /> 
2
<HorizontalScrollView 
    android:id="@+id/vTabs" 
    android:scrollbars="none" 
    android:layout_width="fill_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:background="@color/main_color_gray_dk" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <Button 
      android:enabled="false" 
      android:id="@+id/tab1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/popular" /> 
     <View 
      android:id="@id/view1" 
      android:layout_width="@dimen/pad_1dp" 
      android:layout_height="fill_parent" /> 
     <Button 
      android:id="@id/tab2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/newest" /> 
     <View 
      android:id="@id/view1" 
      android:layout_width="@dimen/pad_1dp" 
      android:layout_height="fill_parent" /> 
     <Button 
      android:id="@id/tab3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/distance" /> 
     <View 
      android:id="@id/view1" 
      android:layout_width="@dimen/pad_1dp" 
      android:layout_height="fill_parent" /> 
     <Button 
      android:id="@+id/tab4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/minimum" /> 
    </LinearLayout> 
</HorizontalScrollView> 

更改文本,以你的口味。 放置在relatveLayout和alignToParentBottom =「true」 希望這可以幫助