笔记 activity 的文本从应用栏后面开始

the text of a notetaking activity starts behind the app bar

该应用运行良好,但当我输入一些笔记时,第一个笔记会消失在应用栏后面。 如何从应用栏下方开始该部分?

3 个注释,只有 2 个可见

xml:

<?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">


<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" />

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Notities">



    <at.markushi.ui.CircleButton
    android:layout_width="64dp"
    android:layout_height="wrap_content"
    app:cb_color="@color/primary"
    app:cb_pressedRingWidth="8dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_action_add"
    android:onClick="openEditorForNewNote"
    android:minWidth="64dp"
    android:minHeight="64dp" />

</RelativeLayout>

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

<!--<Button-->
<!--android:id="@+id/button"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:layout_alignParentEnd="true"-->
<!--android:layout_alignParentRight="true"-->
<!--android:onClick="openEditorForNewNote"-->
<!--android:text="New note" />-->

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

您必须将 ToolBarListView 包装在 RelativeLayout 中,并将 layout_below 属性 赋给 ListView 以便它低于 ToolBar。 像这样,

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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">

    <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" />


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".Notities">

        <include
            android:id="@+id/app_bar"
            layout="@layout/app_bar_notities"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <ListView
            android:id="@+id/android:list"
            android:layout_below="@id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <at.markushi.ui.CircleButton
            android:layout_width="64dp"
            android:layout_height="wrap_content"
            app:cb_color="@color/primary"
            app:cb_pressedRingWidth="8dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_action_add"
            android:onClick="openEditorForNewNote"
            android:minWidth="64dp"
            android:minHeight="64dp" />

    </RelativeLayout>

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

DrawerLayout and AppBar 两者似乎都设置不正确。您的 DrawerLayout 应该只包含两个子项,一个用于主要内容,一个用于抽屉内容。抽屉内容应该在你的 XML 中的主要内容下面,抽屉内容的 layout_width 应该是一个设定的尺寸,通常是 240dp。像这样:

<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 android:id="@+id/content_frame" layout="@layout/content_frame"/>

    <android.support.design.widget.NavigationView android:id="@+id/nav_drawer"
        android:layout_width="@dimen/width_nav_drawer" android:layout_height="match_parent"
        android:layout_gravity="start" android:choiceMode="singleChoice"
        app:headerLayout="@layout/nav_header_main" app:menu="@menu/drawer_main"/>

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

那么你的AppBar应该放在你的content_frame中的CoordinatorLayout中,你的主要内容(你的ListView)放在下面:

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

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

        <android.support.v7.widget.Toolbar android:id="@+id/toobar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:backgroud="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

    <include android:id="@+id/content_main" layout="@layout/content_main"/>

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

最后,您的 ListView(或 RecyclerView)可以放置在您选择的任何布局中(我在这里选择 FrameLayout):

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/layout_main"
    android:layout_width="match_parent" android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <ListView android:id="@+id/list"
        android:layout_width="match_parent" android:layout_height="match_parent"/>

</FrameLayout>

此外,如果您注意到了,我在 FrameLayout 中包含了属性 app:layout_behavior="@string/appbar_scrolling_view_behavior"。这很重要,因为它设置了 AppBarLayout 的行为以及它应该如何对您的 FrameLayout 做出反应。基本上,它使视图位于 AppBar 下方,并且可以在必要时滚动。


旁注:

我还注意到您正在使用来自外部库的 at.markushi.ui.CircleButton。这个库是在 Google 引入包括浮动操作按钮的支持库之前创建的,现在是 deprecated. Since Google has introduced the new FloatingActionButton,你可以在你的 CoordinatorLayout 中使用它作为最后一个元素:

<android.support.design.widget.FloatingActionButton android:id="@+id/btn_action"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_margin="@dimen/margin_standard" android:layout_gravity="end|bottom"
    android:src="@drawable/ic_camera_white_24dp"
    android:onClick="openEditorForNewNote"/>