簡體   English   中英

如何實現水平滾動標簽?

[英]How to implement horizontally scrollable tabs?

我正在嘗試實現此應用程序。 目前我已經設計了標簽,因為我有超過7個標簽,它看起來太擁擠了。 如何設計它以便tabwidget可以水平滾動。 我在市場上的一些應用程序上看到了這個設計,但沒有任何線索如何在我的應用程序中實現這一點。

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

那么有人對此有所了解嗎?

來自Android設計庫的TabLayout

<android.support.design.widget.TabLayout
    android:id="@+id/categories"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tabMode="scrollable" />

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

請查看Jake Wharton的ViewPager應用程序。 這正是你所需要的。 它是一個庫項目,因此您必須將其包含在項目中。

JakeWharton / Android-ViewPagerIndicator

<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”希望這會有所幫助

請訪問此鏈接: https//dzone.com/articles/scrolling-tabs-android

使用Horizo​​ntalScrollView包裝TabWidget,選項卡集將能夠擴展到超出屏幕寬度,用戶可以根據需要左右拖動選項卡:

<?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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM