<span id="Label3"></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">Disclaimer: This article is reproduced from http://blog.csdn.net/bear_huangzhen/article/details/24488337, only the use of their own learning.</span></p></p><p><p><span style="font-size: 16px; font-family: ‘Microsoft YaHei‘;">In the development of <strong>Android</strong> programs, We often use <strong>shape</strong> to define a variety of shapes, first of all we understand what the shape of the label below, it means:</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; background-color: #ff0000;">Solid: Fill</span><br><span style="font-family: ‘Microsoft YaHei‘;">ANDROID:COLOR Specifies the color of the fill</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;"></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; background-color: #ff0000;">Gradient: Gradient</span><br><span style="font-family: ‘Microsoft YaHei‘;">Android:startcolor and Android:endcolor are the starting and ending colors, respectively,</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">Android:angle is a gradient angle and <span style="background-color: #ff0000;">must be an integer multiple of 45. </span></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">In addition, the default mode of the gradient is android:type= "linear", that is, linear gradient,</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">You can specify a gradient as a radial gradient, android:type= "radial", and a radial gradient that requires a radius of android:gradientradius= "50".</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">Angle value corresponding to the location</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;"></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;"></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;"></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; background-color: #ff0000;">Stroke: Stroke</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">Android:width= the width of the "2dp" stroke, android:color the color of the Stroke.</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">We can also make the stroke into a dashed form, set in the following way:</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">Android:dashwidth= "5dp"</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">android:dashgap= "3dp"</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">Where android:dashwidth represents the width of a horizontal line such as '-', Android:dashgap represents the distance separated by</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;"></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; background-color: #ff0000;">Corners: rounded Corners</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">The Android:radius is the radian of the angle, and the larger the value the greater the Rounded.</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">We can also set the four corners to different angles,</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">The RADIUS attribute is not valid if you set five properties at the same time</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">android:radius= "20dp" Sets the radius of Four Corners</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">android:topleftradius= "20dp" Sets the radius of the upper-left corner</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">android:toprightradius= "20dp" Set the radius of the upper-right corner</span></p></p><p><p><em id="__mceDel" style="line-height: 1.5;"><em id="__mceDel"><em id="__mceDel"><span style="font-family: ‘Microsoft YaHei‘;">android:bottomleftradius= "20dp" Setting the radius of the lower right corner</span></em></em></em></p></p><p><p><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><span style="font-family: ‘Microsoft YaHei‘;">android:bottomrightradius= "20dp" Set the radius of the lower left corner</span></em></em></em></p></p><p><p></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘; background-color: #ff0000;">Padding: interval</span><br><span style="font-family: ‘Microsoft YaHei‘;">You can set the interval between the top and left four directions</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;"></span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">here, Let's look at a simple example where two XML files are defined under the drawable folder:</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;">The contents of Border.xml are as Follows:</span></p></p><p><p><span style="font-family: ‘Microsoft YaHei‘;"></span></p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"><?xml version= "1.0" encoding= "utf-8"? ><shape xmlns:android= "http://schemas.android.com/apk/res/android" > <solid android:color= "#0000"/> <stroke android:width= "4px" android:color= "#f00"/></ Shape></pre></pre><p><p> </p></p><p><p>Border2.xml content is as Follows:</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"><?xml version= "1.0" encoding= "utf-8"? ><shape xmlns:android= "http://schemas.android.com/apk/res/android" android:shape= "rectangle" > <corners android:radius= "20px"/> <stroke android:width= "4px" android:color= "#f0f"/> <gradient android:startcolor= "#f00" android:centercolor= "# 0f0 " android:endcolor=" #00f " android:type=" sweep "/></shape></pre></pre><p><p> </p></p><p><p>Layout/main.xml:</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"><?xml version= "1.0" encoding= "utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:orientation=" vertical " android:layout_width=" match_parent " android:layout_height= "match_parent" > <textview android:layout_width= "match_parent" android:layout_height= "wrap_ Content " android:text=" with border text " android:textsize=" 24pt " android:background=" @drawable/border "/> <textview android:layout_width= "match_parent" android:layout_height= "wrap_content " android:text= "rounded border" android:textsize= "24pt" android:background= "@drawable/border2"/></ Linearlayout></pre></pre><p><p> </p></p><p><p>The effect is as Follows:</p></p><p><p></p></p><p><p></p></p><span style="font-family: ‘Microsoft YaHei‘;"><span style="font-family: ‘Microsoft YaHei‘;"><strong> </strong></span></span><span style="font-family: ‘Microsoft YaHei‘;"><span style="font-family: ‘Microsoft YaHei‘;"><strong>This code is useless to the padding property and the stroke property, borrowing someone else's</strong></span></span><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"><stroke android:width= "2dp" android:color= "#fad3cf"/> <!--defines The width of the stroke and the color value of the stroke- <br><br><em id="__mceDel" style="font-size: 13px; font-family: verdana, Arial, Helvetica, sans-serif; line-height: 1.5;"><span class="tag"><<span class="tag-name">padding<br></span></span></em><em id="__mceDel" style="font-size: 13px; font-family: verdana, Arial, Helvetica, sans-serif; line-height: 1.5;"><span class="attribute">android:bottom=<span class="attribute-value">"10dp"</span></span></em></pre></pre><p><p><span class="attribute">android:left=<span class="attribute-value">"10dp"</span></span></p></p><p><p><span class="attribute"><span class="attribute-value"> </span></span><em id="__mceDel" style="line-height: 1.5;"><span class="attribute">android:right=<span class="attribute-value">"10dp"</span></span></em></p></p><p><p><em id="__mceDel" style="line-height: 1.5;"><span class="attribute"><span class="attribute-value"> </span></span></em> <em id="__mceDel" style="line-height: 1.5;"> <span class="attribute">android:top=<span class="attribute-value">"10dp" <span class="tag">/> <span class="comments"><!--set The intervals in each direction--</span> </span> </span> </span></em></p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"><br></pre></pre><p><p> </p></p><p><p>A summary of shape usage in Android</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.