【问题标题】:Fragment contents are overlapping on ActionBar in Navigation Drawer片段内容在 Navigation Drawer 中的 ActionBar 上重叠
【发布时间】:2015-12-06 08:35:06
【问题描述】:

为什么Fragment 布局会像这样与ActionBar 重叠

  1. FirstFragment

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FirstFragment">
    
    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_first_fragment" />
    

  2. SecondFragment

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_second_fragment" />
    

activity_navigation

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_navigation"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_navigation"
        app:menu="@menu/activity_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

app_bar_navigation

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:fitsSystemWindows="true"
    tools:context="com.example.sup.slideup.Navigation">

    <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="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <FrameLayout
        android:id="@+id/main_fragment_holder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>

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

使用KitKat 设备。

【问题讨论】:

  • 发布您的活动 xml...
  • @RishadAppat:看看。

标签: android android-fragments android-actionbar navigation-drawer


【解决方案1】:

如果您想在 Activity 布局中保持非线性布局,您需要在包含您的 FragmentFrameLayout 上设置一个 layout_marginTop。在你的app_bar_navigation.xml:

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

<FrameLayout
    android:id="@+id/main_fragment_holder"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_marginTop="?attr/actionBarSize"
    />
...

【讨论】:

  • android:layout_marginTop="?attr/actionBarSize" 是完美的......谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-13
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多