【问题标题】:TabLayout in Navigation Drawer is overlapping the Tolbar导航抽屉中的 TabLayout 与工具栏重叠
【发布时间】:2018-09-15 01:26:14
【问题描述】:

我使用了导航抽屉活动并实现了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"  />

【问题讨论】:

  • android:layout_marginTop="?attr/actionBarSize" 。尝试在您的工具栏标签上设置这一行
  • 你能分享一下屏幕截图的样子吗?
  • 感谢您考虑我的问题,但它不起作用@Abhishek
  • 感谢您考虑我的问题,我已经编辑了问题并添加了屏幕截图@AbdulWaheed

标签: android navigation-drawer android-tablayout


【解决方案1】:

实际上是因为你有两个AppBarLayouts,哪个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>

【讨论】:

  • 根据您的回答,我从 content_main 中删除了 AppBarLayout,并在 app_bar_main 中实现了您的回答,但没有任何改变。
【解决方案2】:

请更正“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"  />

【讨论】:

  • 当有人添加RelativeLayout 时它会起作用,否则,在CoordinatorLayout 内它可能表明它没用,所以实际上没有效果..
  • 因此您可以设置样式并使其成为无操作栏,以便允许您自定义操作栏。
  • 这是必须的,否则tabLyout会覆盖下面的内容
猜你喜欢
  • 2017-04-14
  • 2014-12-23
  • 1970-01-01
  • 2015-02-26
  • 2015-01-15
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多