我想要一个应该在视图之外的图像视图。我试过负边距。但无法获得所需的输出。图像被父布局切断。不确定实现所需输出的正确方法是什么。任何指导将不胜感激。
我的代码
<?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
孩子使用您的 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 上查看此链接以获取更多阅读
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句