Android 布局\工具栏和布局之间的定位

Android 布局\工具栏和布局之间的定位,android,android-layout,Android,Android Layout,我希望视图定位在AppBarLayout和layout之间。我只在Android Studio editor上看到这种行为,但在真实设备上则不同,如下所示: 我真的很困惑。我的代码是: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk

我希望视图定位在AppBarLayout和layout之间。我只在Android Studio editor上看到这种行为,但在真实设备上则不同,如下所示:

我真的很困惑。我的代码是:

<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"
    tools:context="view.activity.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/bar_layout"
    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" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="84dp"
        android:layout_marginTop="@dimen/activity_vertical_margin">

      <!--views on toolbar-->

    </RelativeLayout>

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

<include layout="@layout/activity_home_content" />

<RelativeLayout
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_marginStart="@dimen/activity_horizontal_margin"
    android:background="@drawable/circle_accent"
    app:layout_anchor="@+id/whole_layout"
    app:layout_anchorGravity="top|start">

    <!--img view-->
</RelativeLayout>

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

和“活动\u主页\u内容”

<LinearLayout 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/whole_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="view.activity.MainActivity"
tools:showIn="@layout/activity_home_toolbar">


<!--some other views-->

</LinearLayout>

刚刚试过。正如我在评论中提到的,您的
整体布局
是一个
线性布局
,标高为0dp。默认情况下,您锚定到此
线性布局的任何图元将收到0dp的高程(与您锚定到的视图相同)。这意味着
RelativeLayout
的高程为0dp

AppBarLayout
的高程为4dp,因此默认情况下,
RelativeLayout
将始终在其下方绘制

修复程序

为相对布局指定大于或等于4的高程。这将解决您的问题,除了
RelativeLayout
现在也会投下阴影

以下是
RelativeLayout

<RelativeLayout
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_marginStart="@dimen/activity_horizontal_margin"
    android:background="@drawable/circle_accent"
    app:layout_anchor="@+id/whole_layout"
    app:layout_anchorGravity="top|start"
    android:elevation="4dp">

    <!--img view-->

</RelativeLayout>


不确定,但我认为将“AvatarView”的标高更改为AppBarLayout的标高应该更高work@AjilO. 更改高程是什么意思?我将app:layout_-anchor=“@+id/whole_-layout”app:layout_-anchorGravity=“top | start”
放入以实现所需的行为。但是
整个_布局
将被放置在
AppBarLayout
下面。我没有证实;但我相信默认情况下,
AppBarLayout
的提升高度为8dp。其中,线性布局(
整个布局
)将处于0dp高程。您尝试锚定的
RelativeView
也通过默认值将其提升为0dp,但仍然不适用于我。在我将其滚动到顶部后,它会显示在应用程序栏下方