简体   繁体   English

如何实现水平滚动标签?

[英]How to implement horizontally scrollable tabs?

I'm trying to implement this application. 我正在尝试实现此应用程序。 At the moment I have designed tabs on it and since I have more than 7 tabs it looks too congested. 目前我已经设计了标签,因为我有超过7个标签,它看起来太拥挤了。 How can I design it so that the tabwidget is scrollable horizontally. 如何设计它以便tabwidget可以水平滚动。 I have seen this design on few of the apps at the market but no clue how to implement this in my app. 我在市场上的一些应用程序上看到了这个设计,但没有任何线索如何在我的应用程序中实现这一点。

One app I saw had a horizontal scrollview where it scrolls on its own and when you press the particular image/button it displays some content. 我看到的一个应用程序有一个水平滚动视图,它自己滚动,当你按下特定的图像/按钮时,它会显示一些内容。 It didn't seem to be tabs I guess. 它似乎不是我猜的标签。

So does anyone have an idea of this? 那么有人对此有所了解吗?

TabLayout from Android design library 来自Android设计库的TabLayout

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

This is a pretty good example by using HorizontalScrollView. 这是使用Horizo​​ntalScrollView的一个很好的例子。 http://java.dzone.com/articles/scrolling-tabs-android http://java.dzone.com/articles/scrolling-tabs-android

Please check out Jake Wharton's ViewPager app. 请查看Jake Wharton的ViewPager应用程序。 That is exactly what you need. 这正是你所需要的。 It is a library project, so you have to include it in your project. 它是一个库项目,因此您必须将其包含在项目中。

JakeWharton / Android-ViewPagerIndicator 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>

Change Texts to your taste. 根据您的口味更改文本。 Place in a relatveLayout and alignToParentBottom="true" Hope this helps 放在relatveLayout和alignToParentBottom =“true”希望这会有所帮助

Check this link: https://dzone.com/articles/scrolling-tabs-android 请访问此链接: https//dzone.com/articles/scrolling-tabs-android

Wrap your TabWidget with a HorizontalScrollView and the tab set will be able to expand beyond the width of the screen and the user can drag the tabs left and right as required: 使用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