简体   繁体   English

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

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

I want to create a drawable android XML Background as shown in the Figure could anybody please tell me how to do this. 我想创建一个可绘制的android XML背景,如图所示,任何人都可以告诉我如何执行此操作。 Thank You!! 谢谢!! The Picture of Background is enclosed below 下面是背景图片 在此处输入图片说明

You can easily achieve this using Vector Drawables. 您可以使用Vector Drawables轻松实现这一目标。 Just create a file background.xml and paste the following code: 只需创建一个文件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,-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,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.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>

You can change the color by changing the color code of fillColor . 您可以通过更改fillColor的颜色代码来更改颜色。

Note: You can do the same with any PNG image. 注意:您可以对任何PNG图片执行相同的操作。 Convert the png image to svg HERE . png图像转换为svg HERE Then in Android Studio go to File>New>Vector Asset>Local File(SVG,PSD)>Finish 然后在Android Studio中转到“ 文件”>“新建”>“矢量资产”>“本地文件(SVG,PSD)”>“完成”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM