android - 如何在android中适应制表符宽度屏幕

标签 android android-support-library android-tablayout

我使用 android 支持库实现选项卡布局,它看起来像

enter image description here

这里的标签宽度不适合屏幕,我的布局是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white" />

</LinearLayout>

最佳答案

尝试在您的 TabLayout 上调用这些方法:

tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

关于android - 如何在android中适应制表符宽度屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32305076/

相关文章:

java - 将文件复制到 Assets 文件夹

android - 如何使用新的 Dropbox API 下载文件?

android - 错误 : package android. support.annotation 不存在 - Android 工作室 - Gradle

android - 工具栏在 TabLayout 上投下阴影

android - WebView的restorePicture方法——防止webview重新加载页面

安卓棉花糖 : How to allow Runtime Permissions programatically?

Android vectorDrawables.useSupportLibrary = true 正在停止应用

android - "Cannot resolve class android.support.v4.widget.DrawerLayout"即使在 gradle 中添加依赖项之后

android - 如何在 Android 中为底部导航设置全宽

android - 更改 TabLayout 选项卡位置