自定义内容始终位于选项卡布局的中心。
选项卡布局如下所示。
如何使其占用父元素 TabView 的所有可用空间。
在下面添加一个文本视图:
很不幸,它总是居中且无法占满整个空间。问题在于我无法提供选项卡之间的分隔符,因为它总是居中。
Java代码添加选项卡:
<android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tablayout"
android:layout_width="match_parent"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
android:layout_height="90dp">
</android.support.design.widget.TabLayout>
在下面添加一个文本视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_purple"
android:gravity="center_horizontal">
<TextView
android:text="Hello !"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
很不幸,它总是居中且无法占满整个空间。问题在于我无法提供选项卡之间的分隔符,因为它总是居中。
Java代码添加选项卡:
TabLayout v = (TabLayout)findViewById(R.id.tablayout);
TabLayout.Tab tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab);
tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab);
tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab)
我分享了这张图片 @http://i60.tinypic.com/11cdvyf.jpg
。