Android 增加选项卡布局中选项卡的宽度

Android 增加选项卡布局中选项卡的宽度,android,android-viewpager,adapter,android-tablayout,Android,Android Viewpager,Adapter,Android Tablayout,大家好 我正在从事安卓材质设计 当我向适配器添加模式选项卡时,文本会被扭曲,分成两个位置,如图所示。 我的代码: 我的XML <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer"

大家好

我正在从事安卓材质设计

当我向适配器添加模式选项卡时,文本会被扭曲,分成两个位置,如图所示。 我的代码:

我的XML

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
        </android.support.design.widget.AppBarLayout>
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|bottom"
            android:layout_marginBottom="@dimen/md_keylines"
            android:layout_marginRight="@dimen/md_keylines"
            app:srcCompat="@drawable/ic_add"
            android:tint="@color/white"/>
    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/navheader"
        app:menu="@menu/menu_navigation" />
</android.support.v4.widget.DrawerLayout>

如何增加选项卡宽度,以确保6主页、屏幕1、屏幕2等在一行中,即宽度更大,而不是两行?

设置app:tabMode=“scrollable”for android.support.design.widget.TabLayout in layout in layout file


  <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"/>
以编程方式设置

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

XML


如果不符合您的要求,请记下

将tabMode设置为可滚动,然后重试。在此处发布您的xml我也发布了我的xml。替换为:-->谢谢。当我们从主页导航到屏幕1到屏幕2等等时,如何更改选项卡颜色?比如说,当我在第二屏上时,我希望一切都是橙色的。我怎么能这么做?你需要换一下themeThanks。我应该动态设置吗?您可以设置OnPageChange。我还需要以下内容:当我从主页导航到屏幕1或从屏幕1导航到屏幕2时,更改颜色或主题。我该怎么做?你能给我举个例子吗app:tabGravity=“fill”不适用于app:tabMode=“scrollable”。我只适用于app:tabMode=“fixed”
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
            app:tabGravity="fill"
            app:tabMode="scrollable"