我正在尝试创建一个选项卡布局
,它有两个选项卡
。当我在小型移动设备上运行该应用程序时,选项卡布局
看起来不错,但当我在平板电脑
上运行相同的应用程序时,它显示如下。
在平板电脑上看起来像这样:
我希望每个选项卡占据整个空间,两端没有任何间隙。我创建了这样的标签布局
...
private void drawTabLayout() {
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.addTab(tabLayout.newTab().setText("Imprint") );
tabLayout.addTab(tabLayout.newTab().setText("Legal"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setSelectedTabIndicatorHeight(10);
tabLayout.setBackgroundColor(Color.WHITE);
}
我搜索了很多网站,但找不到正确的答案。
最佳答案
将此代码添加到您的 tab_layout.xml
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed" />
希望它对你有用...
关于java - 如何在 Tab 布局中设置 Tab 宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35336641/