如何制作底部带阴影的圆角图片视图

3
我希望将我的ImageView底部弯曲,并具有阴影效果。
类似于这张图片。

enter image description here

但我不知道如何实现这一点。

每当我在Google或StackOverflow上搜索时,它都会显示与弧形边角相关的结果,但我想要底部有弧形边缘。

1个回答

0

你可以使用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>

它显示为这样。

enter image description here

然后在后台使用这个。

<?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>

它就像这样。

enter image description here

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

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


这很完美,但如何在形状内添加图像而不仅仅是红色? 图像是动态添加到视图中的,而不是来自资源。这是我尝试过的: https://photos.app.goo.gl/QHbosfA1G5iKWg5q6 - Amol Barge
你使用过图片库吗?例如Glide - S T
然后你需要制作像透明孔洞一样的图像。这意味着红色部分应该是透明的,而外部部分应该是白色的。并将图像设置在其中。就像这个 https://dev59.com/TWgu5IYBdhLWcg3wln8O#11227247 - S T
我认为设计师可以做到。 - S T

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接