android - 笔记 Activity 的文本从应用栏后面开始

标签 android android-studio appbar behind

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

3 个注释,只有 2 个可见 3 notes, only 2 visible

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>

最佳答案

DrawerLayoutAppBar两者似乎都设置不正确。您的 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_frameCoordinatorLayout 中,你的主要内容(你的 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 使用react。基本上,它使 View 位于 AppBar 下方,并且可以在必要时滚动。


旁注:

我还注意到您正在使用来自外部库的 at.markushi.ui.CircleButton。这个库是在 Google 引入支持库(包括 float 操作按钮)之前创建的,现在是 deprecated .由于谷歌推出了新的 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"/>

关于android - 笔记 Activity 的文本从应用栏后面开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34812531/

相关文章:

android - Android 中如何计算网站速度

android - 旋转端口登陆Android4.X后如何避免在智能手机中剪切/复制/粘贴?

java - Android:启动相机应用程序现在会使应用程序崩溃

c# - 如何在 C# Metro 应用程序的 AppBar 中聚焦文本框?

flutter 删除应用栏上的后退按钮

android - 为什么这不会导致崩溃?我正在从其他线程更新 UI

java - Android Studio : Problems accessing Sub-Item in non activity class

Android Studio 项目需要旧版本的 Gradle

Android Studio 在进行 NDK 开发时卡在 macOS 上

java - 如何为每个不同的 fragment 设置操作栏