导航抽屉中的TabLayout与工具栏重叠

时间:2018-09-14 06:51:42

标签: android navigation-drawer android-tablayout

我已经使用了导航抽屉活动并实现了TabLayout,但是当应用程序运行时,只有工具栏的布局布局才可见,而工具栏却不可见。但是在预览窗格的工具栏中可见,这是在设备上运行此应用程序时发生的。请帮帮我

这是app_bar_main.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorToolbar"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp"
        >

        <ImageView
            android:layout_width="@dimen/_40sdp"
            android:layout_height="match_parent"
            android:src="@drawable/logo_shopline"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="ShopLine"
            android:gravity="center"
            android:textSize="@dimen/_18sdp"
            android:textColor="@color/colorShopLineText"
            android:paddingLeft="@dimen/_2sdp"
            />

    </android.support.v7.widget.Toolbar>


</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

这里是content_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main">

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

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="@dimen/custom_tab_layout_height"
        app:tabMode="fixed"
        app:tabGravity="fill"
        />
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/appBarLayout"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"  />

Here is the screen shot

2 个答案:

答案 0 :(得分:0)

实际上是因为您拥有两个AppBarLayout,而android可能无法识别您编写的布局。

只需删除另一个AppBarLayout并按如下所示进行布局即可:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorToolbar"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp">

        <ImageView
            android:layout_width="@dimen/_40sdp"
            android:layout_height="match_parent"
            android:src="@drawable/logo_shopline" />  

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="ShopLine"
            android:gravity="center"
            android:textSize="@dimen/_18sdp"
            android:textColor="@color/colorShopLineText"
            android:paddingLeft="@dimen/_2sdp" />

    </android.support.v7.widget.Toolbar>

 <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="@dimen/custom_tab_layout_height"
        android:layout_gravity="bottom"
        app:tabMode="fixed"
        app:tabGravity="fill" />

</android.support.design.widget.AppBarLayout>

答案 1 :(得分:0)

请更正“ layout_below”

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

android:layout_below =“ @ + id / appBarLayout”

  app:layout_behavior="@string/appbar_scrolling_view_behavior"  />