我正在使用下面的代码来圆化 RelativeLayout 的角。我将其保存为 mybackground.xml
在 drawable
文件夹中。
它可以很好地圆角,但问题是我还想添加一个透明图像作为我的 RelativeLayout 的背景。我怎样才能实现这两件事?如何在 RelativeLayout 中同时使用图像和可绘制的 xml(用于圆角)...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
最佳答案
使用Layer List和Item标签设置Image,使用solid标签设置颜色为#AA000000透明如下图
<?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" android:padding="10dp">
<solid android:color="#AA000000"/>
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/yourfilename"/>
</item>
</layer-list>
关于android - 设置背景图像和 xml 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6609828/