是否可以像图片一样从 xml 创建可绘制对象?第一个矩形包含第二个矩形。
如果是,请向我解释如何。
如果您想要简单的矩形,您可以使用具有两个形状的LayerList作为内容:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#a1a1a1" />
</shape>
</item>
<item android:top="5dp" android:right="5dp" android:bottom="5dp"
android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#f1f1f1" />
</shape>
</item>
</layer-list>