如何在Tab布局中设置Tab宽度? [英] How to set Tab width in Tab layout?

查看:1879
本文介绍了如何在Tab布局中设置Tab宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个标签布局,它有两个标签。当我在小型手机上运行应用程序时,标签布局看起来不错,但是当我在平板电脑上运行相同的应用程序时,它显示像这样。

I'm trying to create a tab layout which has two tabs. When I run the app on small mobile the tab layout looks fine but when I run the same application on Tablet it shows like this.

它看起来像这样平板电脑

我希望每个标签占据整个空间,两端都没有任何间隙。我创建了标签布局,就像这样......

I want each tab to occupy entire space without any gaps on both the ends. I have created tab layout like this...

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);
}

我搜索了很多网站,但找不到合适的回答即可。
提前致谢。

I have searched many sites but couldn't find the right answer. Thanks in advance.

推荐答案

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" />

希望它适合你...

这篇关于如何在Tab布局中设置Tab宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆