【发布时间】:2018-11-09 19:00:40
【问题描述】:
我正在尝试为ImageView 创建一个shape,它有圆角、实际的image 和一个阴影。当我创建 shape 并设置以下变量时,我得到了一个带有阴影的圆形图像:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#42000000" />
<corners android:radius="5dp" />
</shape>
现在,当我尝试添加自定义图像时(就像许多人建议我使用 Layer-list 一样,我得到了图像,但圆角和阴影消失了:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#42000000" />
<corners android:radius="5dp" />
</shape>
</item>
<item android:drawable="@drawable/no_cover_art" />
</layer-list>
我还将以编程方式更改“图像”,所以也许这也是需要提及的事情。
我做错了什么,如何获得带有阴影和自定义图像的圆角?
编辑
我曾尝试仅将形状用作可绘制对象,但我得到的结果是将角应用于其后面的东西并且不会更改 ImageView 本身。
<ImageView
android:id="@+id/song_album_cover"
android:layout_width="64dp"
android:layout_height="68dp"
android:layout_marginStart="8dp"
android:layout_marginTop="6dp"
android:elevation="18dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/no_cover_art"
android:background="@drawable/artist_cover_image"/>
左侧是Android Studio 向我展示的图片,右侧是我实际运行应用程序时的图片。
【问题讨论】:
标签: android xml drawable shapes