【发布时间】:2016-08-23 09:16:53
【问题描述】:
TabLayout 为 viewpager 构建一个滑动选项卡非常有用,除了据我所知,您无法像 TabHost 在代码或 xml 中那样在选项卡之间添加垂直线,所以还有其他方法可以轻松做到这一点?
【问题讨论】:
-
您可以尝试以下链接来解决您的问题。链接:stackoverflow.com/questions/32204184/…
标签: android
TabLayout 为 viewpager 构建一个滑动选项卡非常有用,除了据我所知,您无法像 TabHost 在代码或 xml 中那样在选项卡之间添加垂直线,所以还有其他方法可以轻松做到这一点?
【问题讨论】:
标签: android
TabLayout 实际上是一个水平可滚动的LinearLayout。
只需使用以下代码添加分隔符:
LinearLayout linearLayout = (LinearLayout)tabLayout.getChildAt(0);
linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
GradientDrawable drawable = new GradientDrawable();
drawable.setColor(Color.GRAY);
drawable.setSize(1, 1);
linearLayout.setDividerPadding(10);
linearLayout.setDividerDrawable(drawable);
【讨论】:
com.google.android.material.tabs.TabLayout 这是HorizontalScrollView
试试这个,
您可以在 tab_indicator 布局文件中手动添加行。
对于水平线,
<View
android:layout_height="1dp"
android:id="@+id/line"
android:layout_width="fill_parent"
android:background="your color" />
对于垂直线
<View
android:layout_height="7dp"
android:id="@+id/line"
android:layout_width="1dp"
android:background="your color" />
【讨论】: