笔记活动的文本在应用栏后面开始

时间:2016-01-15 13:49:06

标签: android android-studio appbar behind

该应用程序运行良好,除了当我输入一些笔记时,第一个笔记消失在应用栏后面。 如何从应用栏下启动该部分?

3个音符,只有2个可见 John

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>

2 个答案:

答案 0 :(得分:4)

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应放在CoordinatorLayout的{​​{1}}中,主要内容(您的content_frame)放在下方:

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> 中添加了属性app:layout_behavior="@string/appbar_scrolling_view_behavior"。这很重要,因为它设置了FrameLayout的行为以及它应该如何对您的AppBarLayout作出反应。基本上,它使得视图低于FrameLayout,并且可以在必要时滚动。

旁注:

我还注意到您正在使用外部库中的AppBar。此库是在Google推出包含浮动操作按钮的支持库之前创建的,现在是deprecated。由于Google引入了新的FloatingActionButton,您可以在at.markushi.ui.CircleButton中将其用作最后一个元素:

CoordinatorLayout

答案 1 :(得分:0)

您必须将ToolBarListView包裹在RelativeLayout中,并将layout_below属性提供给ListView,使其低于{{1} }}。 像这样的东西,

ToolBar