我正试图实现这个应用程序。目前我已经设计了选项卡,因为我有超过7个选项卡,它看起来过于拥挤。我如何设计它,以便tabwidget可水平滚动。我已经在市场上的几款应用中看到过这种设计,但不知道如何在我的应用中实现这一点。如何实现水平滚动的标签?
我看到的一个应用程序有一个水平滚动视图,它自己滚动,当您按下特定图像/按钮时,它会显示一些内容。它似乎没有我猜的标签。
那么有没有人有这个想法?
我正试图实现这个应用程序。目前我已经设计了选项卡,因为我有超过7个选项卡,它看起来过于拥挤。我如何设计它,以便tabwidget可水平滚动。我已经在市场上的几款应用中看到过这种设计,但不知道如何在我的应用中实现这一点。如何实现水平滚动的标签?
我看到的一个应用程序有一个水平滚动视图,它自己滚动,当您按下特定图像/按钮时,它会显示一些内容。它似乎没有我猜的标签。
那么有没有人有这个想法?
请查看Jake Wharton的ViewPager应用程序。这正是你需要的。这是一个图书馆项目,所以你必须将它包含在你的项目中。
这是通过使用HorizontalScrollView一个很好的例子。 http://java.dzone.com/articles/scrolling-tabs-android
嗨卡尔文感谢您的文章它为我工作。我正在开发平板电脑的应用程序。但标签不占用文本的宽度>。希望你明白我的意思是它看起来全部拥塞我可以为选项卡sot帽子定义一个宽度,它包含完整的文本。例如:如果有一个标签显示“User Profile”,但只显示为“User” – 2012-03-14 15:34:34
检查此链接:https://dzone.com/articles/scrolling-tabs-android
包装你TabWidget用HorizontalScrollView和标签集将 能够扩展超出屏幕的宽度,并且用户可以拖动 标签左右要求:
<?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>
TabLayout从Android的设计库
个<android.support.design.widget.TabLayout
android:id="@+id/categories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
<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” 希望这可以帮助
嗨卡尔文感谢您的文章它为我工作。我正在开发平板电脑的应用程序。但标签不占用文本的宽度>。希望你明白我的意思是它看起来全部拥塞我可以为选项卡sot帽子定义一个宽度,它包含完整的文本。例如:如果有一个选项卡显示“用户配置文件”,但它只显示为“用户” – 2012-03-14 15:34:13
@roses_r只是从库的类TabPageIndicator中删除onMeasure(int,int)方法。有用。 – alu 2015-10-19 07:32:54