【发布时间】:2016-04-24 23:39:22
【问题描述】:
我正在关注this tutorial,它解释了如何实现 Google 设计支持库中包含的新 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 后,应用的外观如下:
我需要它们来填充宽度。
这个问题不是重复的。另一个答案没有解决我的问题。
【问题讨论】:
标签: android androiddesignsupport