Eg1: shape makes Android components display special effects
Layout file used
View plaincopyprint? <? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: Orientation = "vertical"
Android: Background = "# ffffff"
Android: gravity = "center_horizontal">
<Textview
Android: Id = "@ + ID/text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "unused effects"
Android: layout_margintop = "30dp"
/>
<Edittext
Android: Id = "@ + ID/edit"
Android: layout_width = "280dp"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "effect not used effect"
Android: cursorvisible = "true"
/>
<Textview
Android: Id = "@ + ID/text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "effects"
Android: layout_margintop = "10dp"
/>
<Edittext
Android: Id = "@ + ID/edit2"
Android: layout_width = "280dp"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "use effect"
Android: Background = "@ drawable/shape"
Android: cursorvisible = "true"
/>
</Linearlayout>
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: Orientation = "vertical"
Android: Background = "# ffffff"
Android: gravity = "center_horizontal">
<Textview
Android: Id = "@ + ID/text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "unused effects"
Android: layout_margintop = "30dp"
/>
<Edittext
Android: Id = "@ + ID/edit"
Android: layout_width = "280dp"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "effect not used effect"
Android: cursorvisible = "true"
/>
<Textview
Android: Id = "@ + ID/text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "effects"
Android: layout_margintop = "10dp"
/>
<Edittext
Android: Id = "@ + ID/edit2"
Android: layout_width = "280dp"
Android: layout_height = "wrap_content"
Android: textcolor = "#000000"
Android: text = "use effect"
Android: Background = "@ drawable/shape"
Android: cursorvisible = "true"
/>
</Linearlayout>
Used shape File
Shape Functions
Gradient sets the background color gradient.
Startcolor start color value
Endcolor end color value
Angle is gradient Angle
Set the padding between the content in the widget and the border in the widget.
Stroke sets the widget border. Width indicates the Border width, and color indicates the border color.
[Java] view plaincopyprint? <? XML version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: Android = "http://schemas.android.com/apk/res/android">
<Corners
Android: radius = "10dp"
/>
<Gradient
Android: startcolor = "#33cc00"
Android: endcolor = "#666600"
Android: angle = "45"
/>
<Padding
Android: Left = "5dp"
Android: Top = "5dp"
Android: Right = "5dp"
Android: Bottom = "5dp"
/>
<Stroke
Android: width = "3dp"
Android: color = "# ff3300"
/>
</Shape>
<? XML version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: Android = "http://schemas.android.com/apk/res/android">
<Corners
Android: radius = "10dp"
/>
<Gradient
Android: startcolor = "#33cc00"
Android: endcolor = "#666600"
Android: angle = "45"
/>
<Padding
Android: Left = "5dp"
Android: Top = "5dp"
Android: Right = "5dp"
Android: Bottom = "5dp"
/>
<Stroke
Android: width = "3dp"
Android: color = "# ff3300"
/>
</Shape>
Eg2:
<? XML version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: Android = "http://schemas.android.com/apk/res/android">
<! -- Fill -->
<Solid
Android: color = "# b2b2b2"
/>
<! -- Size -->
<Size
Android: width = "200dp"
Android: Height = "50dp"
/>
<! -- Gradient -->
<Gradient
Android: startcolor = "# dbdcdd"
Android: endcolor = "# b8b9bb"
Android: centercolor = "# adadaf"
Android: Angular = "270"
/>
<! -- Stroke -->
<Stroke
Android: width = "2dp"
Android: color = "#3d4148"
/>
<! -- Rounded corner -->
<Corners
Android: radius = "5dp"
/>
<Padding
Android: Left = "10dp"
Android: Top = "10dp"
Android: Right = "10dp"
Android: Bottom = "10dp"
/>
</Shape>
<! --
1. Solid
Description: internal filling.
Property Android: color fill color
2. Size
Description: Size: size.
Attribute:
Android: width indicates the shape width.
Android: height indicates the height of the shape.
3. Gradient
Description: gradient.
Attribute:
Android: startcolor start color
Android: endcolor end color
Android: angle gradient angle (PS: When angle = 0, the gradient is from left to right. Then it turns counter-clockwise. When angle is 90, it goes from bottom to top. Angle must be an integer multiple of 45)
Android: Type gradient type (value: linear, radial, and sweep)
Linear linear gradient, which is the default setting
Radial radioactive gradient, centered on the start color.
Sweep line gradient.
Android: The Middle color of the centercolor gradient, that is, the color between the start color and the end color.
Android: uselevel: If you want to use the levellistdrawable object, set it to true. Set to true without gradient. False indicates gradient.
Android: gradientradius gradient radius. used only when Android: TYPE = "RADIAL. When Android: TYPE = "RADIAL" is used separately, an error is returned.
Android: relative position of the X-point coordinate of the centerx gradient Center
Android: relative position of the Y coordinate of the centery gradient Center
4. Stroke
Description: stroke is equivalent to the border of the Box Model in HTML.
Attribute:
Android: width stroke width
Android: Color stroke color
Android: dashwidth indicates that the stroke style is the width of the dotted line,
If the value is 0, it indicates a solid line. If the value is greater than 0, it is a dotted line.
Android: dashgap indicates that when the stroke is a dotted line, the interval between the dotted lines is "---".
5. Corners
Description: corners: rounded corner.
Attribute:
Android: radius
Android: radius in the upper left corner of topleftradius
Android: radius in the top-right corner of toprightradius
Note that the two attributes are different:
Android: bottomleftradius lower right corner radius
Android: bottomrightradius radius in the lower left corner
6. padding
Description: The internal margin, that is, the distance between the content and the edge.
Attribute:
Android: Left padding
Android: Top padding
Android: Right padding
Android: Bottom padding
-->