我在跟随this tutorial,它解释了如何实现Google Design Support Library中包含的新TabLayout。这里是我的应用程序:使用设计支持库的选项卡不占用全宽
如可以在上面的截图中可以看出,我的选项卡不会拍摄画面的整个宽度。
我该如何解决?
这里是我的活动的xml: (我的Java代码是一样的一个在the tutorial在下面的代码我tablayout和viewpager是的FrameLayout里面。)
<?xml version="1.0" encoding="utf-8"?>
<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">
<!-- your content layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Toolbar instead of ActionBar so the drawer can slide on top -->
<!-- If you want to have dark background for options buttons remove the popup theme -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<!-- Real content goes here -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<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" />
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/nav_view"
app:headerLayout="@layout/nav_view_header"
app:menu="@layout/nav_view_menu"
app:theme="@style/MyTheme.NavMenu" />
</android.support.v4.widget.DrawerLayout>
编辑:
后加入app:tabGravity="center"
,改变app:tabMode
到fixed
,这里的应用程序的外观:
我需要它们来填充宽度。
此问题不重复。另一个答案没有解决我的问题。
的可能的复制[在TabLayout标签不填满整个动作条( http://stackoverflow.com/questions/30721498/tabs-in-tablayout-not-filling-up-entire-actionbar) – Mohsen