ImageVIew 稍微超出父视图

ImageVIew slightly outside of the parent view

我想要一个应该有一半在视图之外的图像视图。我试过负边距。但无法获得所需的输出。图像被父布局切断。不确定实现所需输出的正确方法是什么。任何指导将不胜感激。

我的代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    tools:context=".Activities.ProfileActivity">


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/margin_padding_size_medium"
        android:padding="@dimen/margin_padding_size_medium"
        android:background="@android:color/holo_blue_bright"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="80dp"
            android:background="@android:color/darker_gray"
            >
            <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="-50dp"
                android:src="@drawable/drawer_background"
                android:scaleType="fitXY"

                />

        </RelativeLayout>
    </FrameLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

这是目标输出

这是我的输出

您应该使用 layout_anchor 作为 CoordinatorLayout children 你的 xml 文件需要像这样

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns: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.support.design.widget.AppBarLayout
        android:id="@+id/materialup.appbar"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

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

    <ImageView
        android:id="@+id/materialup.profile_image"
        android:layout_width="96dp"
        android:layout_height="96dp"
        android:elevation="8dp"
        android:src="@color/black"
        app:layout_anchor="@id/materialup.appbar"
        app:layout_anchorGravity="bottom|center"
        app:layout_scrollFlags="scroll"
        />

    ​

</androidx.coordinatorlayout.widget.CoordinatorLayout>

结果

在 github 上查看此 link 以获得更多阅读内容

https://github.com/saulmm/CoordinatorExamples