如图所示,用矩形和三角形创建Android XML形状

时间:2019-02-13 13:47:20

标签: android android-studio android-layout android-drawable shapes

我想创建一个可绘制的android XML背景,如图所示,有人可以告诉我如何做到这一点。谢谢!! enter image description here

下方附有背景图片

1 个答案:

答案 0 :(得分:1)

您可以使用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,-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-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.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中转到文件>新建>矢量资产>本地文件(SVG,PSD)>完成