[英]how to implement horizontally scrolling tabs using latest design library of android?
[英]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" />
这是使用HorizontalScrollView的一个很好的例子。 http://java.dzone.com/articles/scrolling-tabs-android
请查看Jake Wharton的ViewPager应用程序。 这正是你所需要的。 它是一个库项目,因此您必须将其包含在项目中。
<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
使用HorizontalScrollView包装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.