用矩形和三角形创建 Android XML 形状,如图中的背景

Creating Android XML shape with rectangle and triangle as in figure for Background

我想创建一个drawable android XML 如图所示的背景 谁能告诉我怎么做。谢谢你!!下面附上背景图

您可以使用 Vector Drawables 轻松实现此目的。只需创建一个文件 background.xml 并粘贴以下代码:

<vector android:height="24dp" android:viewportHeight="472"
    android:viewportWidth="302" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#ff008d"
        android:pathData="M0,122.9c0,108.3 0.2,123 1.5,123.5 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.2,0.4 2.1,0.2 2.1,-0.4 0,-0.6 0.7,-0.8 1.5,-0.5 0.8,0.4 1.5,0.1 1.5,-0.6 0,-0.7 0.8,-0.9 2.1,-0.5 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0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.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.6,0.5 2,0.4 1.5,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.3,0.4 2.1,0.2 2.1,-0.5 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.2,0.4 2.1,0.2 2.1,-0.4 0,-0.6 0.7,-0.8 1.5,-0.5 0.8,0.4 1.5,0.1 1.5,-0.6 0,-0.7 0.7,-1 1.5,-0.6 0.8,0.3 1.5,0.1 1.5,-0.5 0,-0.6 0.9,-0.8 2.1,-0.4 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.2,-1 1.4,-0.5 1.2,0.4 2.1,0.2 2.1,-0.4 0,-0.6 0.7,-0.8 1.5,-0.5 0.8,0.4 1.5,0.1 1.5,-0.6 0,-0.7 0.8,-0.9 2.1,-0.5 1.6,0.5 1.9,0.4 1.4,-0.5 -0.5,-0.9 -0.1,-1 1.5,-0.5 1.5,0.5 2,0.4 1.6,-0.4 -0.4,-0.6 -0.2,-1.1 0.3,-1.1 0.8,-0 1.1,-23.5 1.1,-77l0,-77 -151,-0 -151,-0 0,122.9z" android:strokeColor="#00000000"/>
</vector>

您可以通过更改fillColor的颜色代码来更改颜色。

注意:您可以对任何 PNG 图像执行相同的操作。将 png 图像转换为 svg HERE。然后在 Android Studio 中转到 File>New>Vector Asset>Local File(SVG,PSD)>Finish