【发布时间】:2016-01-15 22:40:47
【问题描述】:
自定义始终在 Tablayout 中居中。 标签布局如下。 如何获取其父级可用的全部空间,即 TabView。
<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
【问题讨论】:
标签: android android-design-library android-tablayout