ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 在工具栏下显示内容

2019-09-30 21:36:16  阅读:215  来源: 互联网

标签:android android-toolbar xml android-layout toolbar


您好我试图简单地将我的内容放在工具栏下面,但是当我运行我的应用程序时,当它应该低于它时,一些内容隐藏在它后面.

我已经阅读了关于使用框架布局来尝试将其分开但我已经陷入困境.我目前正在使用随软件提供的基本android studio导航抽屉模板,并想知道我必须做出哪些更改.

我的协调员布局

<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/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

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

我的抽屉布局

<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_main"
    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_main"
    app:menu="@menu/activity_main_drawer" />

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

我需要做出哪些改变?

解决方法:

许多ViewGroups允许他们的孩子重叠.这些包括FrameLayout,RelativeLayout,CoordinatorLayout和DrawerLayout.一个不允许其子项重叠的是LinearLayout.

你的问题的答案实际上取决于最终结果应该是什么.如果你想要一个总是在屏幕上的工具栏和它下面的一些内容,那么你根本不需要CoordinatorLayout和AppBarLayout,你可以使用一个带有两个子节点的垂直LinearLayout:

<LinearLayout android:orientation="vertical" ...>
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        ... />

    <FrameLayout 
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        ... />
</LinearLayout>

注意FrameLayout的布局属性.

如果你想在滚动内容的同时进行工具栏滚动和离开屏幕的花哨的东西,那么你需要一个AppBarLayout,你需要给你的内容区域一个特殊属性,如下所示:

<android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.AppBarLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       ... >

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll"
            ... />
    </android.support.design.widget.AppBarLayout>

    <FrameLayout 
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        ... />
</android.support.design.widget.CoordinatorLayout>

标签:android,android-toolbar,xml,android-layout,toolbar
来源: https://codeday.me/bug/20190930/1836908.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有