繁体   English   中英

如何在底部带阴影的圆形边缘制作图像视图

[英]How to make image view with rounded edge at bottom with shadow

我想让我的 ImageView 在底部弯曲并带有阴影效果。

类似于这张图片

在此处输入图像描述

但我不知道如何做到这一点。

每当我在 Google 或 StackOverflow 上搜索时,它都会向我显示与弯角相关的结果,但我希望底部有弯曲的边缘。

您可以使用layer-list制作形状

例如,

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:left="-150dp"
        android:right="-150dp"
        android:top="-200dp">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="#C72C2F" />
        </shape>
    </item>
</layer-list>

它像这样显示。

在此处输入图像描述

然后在后台使用它,

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">

    <LinearLayout
        app:layout_constraintTop_toTopOf="parent"
        android:background="@drawable/round"
        android:elevation="30dp"
        android:layout_width="match_parent"
        android:layout_height="700dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

它是这样的。

在此处输入图像描述

另外为了制作阴影效果,我使用android:elevation它制作阴影,如果增加值,它可以制作更多深度。

并且显然为显示图像添加了图像视图。 我相信你可以做到这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM