This is not a background, just talk about how to use SVG resources in Android!
Steps to use:
1. source files for SVG resources
To use SVG resources, we first have to have SVG resources, where to find, there are many tools to generate SVG resources, such as the OmniGraffle graphics editor, I generated a picture of an SVG resource
You can see the code after you open it with a browser
All we need is the SVG code after path, and copy it into our code.
M 6.783868 184 C 6.783868 184 7.349524 160.57912 14.131572 157.31086 C 19.783036 155.677 29.389906 150.7756 31.085964 149. 68606 c 32.78275 148.59634 32.78093 143.14954 32.78093 143.69422 C 32.78093 144.23854 20.34669 156.22168 11.870586 156.221 29.9572 c 140.971 27.130012 136.06888 27.130012 136.06888 c 27.130012 136.06888 12.434786 147.50698 9.04267 146.41762 C 24.302642 132.80062 26.565084 126.26464 26.565084 126.26464 c 26.565084 126.26464 7.349524 136.06888 0 132.25594 C 17.523 324 127.35418 22.044022 88.13767 22.044022 88.13767 c 22.044022 88.13767 25.998882 52.18906 28.82607 45.6529 C 29.9572 39. 66178 41.26122-2.27822 91.564273 4.80244 c 141.86809 11.88328 134.52148 75.06544 134.52148 76.69959 C 134.52148 78.333574 135.65042 76.15482 135.65042 81.056866 c 135.65042 85.95886 133.3898 88.13767 133.3898 88.13767 C 133.3898 88.13767 135.6 5133 93.584493 135.65133 102.84378 c 133.955276 101.20983 133.3898 98.486374 132.259764 100.12038 C 131.69538 106.656376 1 30.0006 105.022426 126.6083 117.54976 c 126.041916 124.0861 133.955276 128.98804 136.78028 128.98804 C 131.12918 131.16676 140.1713 132.80062 140. 1713 132.80062 c 140.1713 132.80062 159.38686 135.52402 166.17091 139.88164 C 172.95351 144.23908 181.43398 169.29364 181. 99854 182.91064 C 182.56402 183.99982 6.783868 184 6.783868 184 Z
Here our SVG resources are ready, and then we'll use it in the code.
2. Writing vector drawable resource files
<?xml version= "1.0" encoding= "Utf-8"?><vector xmlns:android="http://schemas.android.com/apk/res/android"Android : Width="600DP"android:height="600DP"android:viewportheight="512" android:viewportwidth="> " <path android:fillcolor= "#410a0a0a"android:pathdata="@string/ Pretty_girl "/> </vector>
Here are some explanations of these properties;
Android:width= "600DP" actually displays a width of 600DP
Android:height= "600DP" The actual height of the display is 600DP
android:viewportheight= "512" vector-qualified width of 512, which has no units;
Android:viewportwidth= "512" vector-qualified height of 512
In fact, the above two properties, is the width of our SVG image
Android:pathdata= "@string/pretty_girl", that is, the path path of the picture content, the value in path generally does not exceed the value of Viewportheight and Viewportwidth, where there is no more than 512
3, using, as with other drawable resource files, directly set the View background or ImageView src resources
<relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" android:layout_width =" match_parent " android:layout_height =; <ImageViewandroid:id="@+id/id_img"android:layout_centerinparent= "true" android:layout_width="Wrap_content"android:layout_height="Wrap_content" android:src="@drawable/pretty_girl"/> </relativelayout>
Run as follows:
This is the right place to be! However, this effect is only supported by Android5.0 and later versions, so it doesn't make much sense to study it, so far it doesn't make much sense! So I was thinking, can the lower version of the system also support SVG vector diagram? The answer is yes. Next Android using SVG resource file (ii) will explain how to use the SVG file in the lower version, if you are interested in SVG friends can continue to pay attention to.
The code is not posted here, because only in the system above Android5.0 can run.
Android using SVG resource file (i)