2016-12-21 19 views
1

我使用Android Studio(抽屉和标签)的布局,标签是在一个片段。标签不是整个屏幕

正如您在下面的屏幕截图中看到的,它们不在工具栏下,并显示在中间。可能是什么问题呢?

制表main.xml中

<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:orientation="vertical" 
    android:layout_height="wrap_content"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     app:tabGravity="fill" 
     app:tabMode="fixed" 
     android:background="@color/material_blue_grey_800" 
     app:tabIndicatorColor="@color/orange" 
     app:tabSelectedTextColor="@color/orange" 
     app:tabTextColor="@color/white" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </android.support.design.widget.TabLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


    </android.support.v4.view.ViewPager> 

</LinearLayout > 
+0

发布您的布局xml – FarshidABZ

+1

从活动/片段创建自动生成的布局现在有paddings = 16dp,只需删除它们 –

+0

You inc这个标签主要xml在某处。显示太 –

回答

0

的选项卡可能无法接受,因为保证金的全宽/容器上的填充在其中添加了TabLayoutViewPager

标签栏也可以是顶部工具栏的一部分。然后这些选项卡将与工具栏样式匹配,因此您可以使用AppBarLayoutsee support lib JavaDocs。在此布局中,您包括一个ToolbarTabLayout

0

添加到您的TabLayout:

应用:tabMode =“固定”

它会告诉布局舒展的标签以适应屏幕 的宽度还要注意的是,如果视图有边距(从视图或父视图)它不会工作