The Drawable of the Android platform represents the resources that can be drawn on the screen. You can use getDrawable (int) to obtain the Drawable resource from the resource file, or use @ drawable in the XML resource file to reference A drawable resource.
Drawable resources can be divided into Bitmap, Nine-Patch, Layer List, State List, Level List, Transition, Insert, Clip, Scale, and Shape.
In this example, GradientDrawable introduces the usage of Sharp Drawable resources:
A Shape resource can define a rectangle, oval, line, ring, and other simple 2D images, you can also use Corners to define attributes such as corner shape, Gradient filling mode, padding, size, solid, and stroke.
The layout resource file in this example is defined as shape_drawable_1.xml as follows:
<ScrollView xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: background = "@ drawable/white">
<LinearLayout
Android: orientation = "vertical"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "50dip"
Android: src = "@ drawable/shape_1"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/line"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "50dip"
Android: src = "@ drawable/shape_2"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/line"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "50dip"
Android: src = "@ drawable/shape_3"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/line"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "50dip"
Android: src = "@ drawable/shape_4"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/line"/>
<ImageView
Android: layout_width = "match_parent"
Android: layout_height = "50dip"
Android: src = "@ drawable/shape_5"/>
</LinearLayout>
</ScrollView>
In the original example, the background color on the simulator is black, causing several shapes to be invisible (these shapes are also drawn in black, so you need to modify this resource, define a drawable white Color Resource:
<Drawable name = "white"> # ffffffff </drawable>
Then, the layout background is defined as white. This resource defines five Shape Drawable resources, separated by a horizontal line @ drawable/line.
Here we only take a look at the Shape5 definition: This corresponds to the Title: GradientDrawable in this example.
<Shape xmlns: android = "http://schemas.android.com/apk/res/android"
Android: shape = "rectangle">
<Gradient android: startColor = "# FFFF0000 ″
Android: endColor = "# 80FF00FF"
Android: angle = "270"/>
<Padding android: left = "7dp" android: top = "7dp"
Android: right = "7dp" android: bottom = "7dp"/>
<Corners android: radius = "8dp"/>
</Shape>
The Shape is similar to the rectangle, which defines the gradient angle as 270 degrees (must be an integer multiple of 90) and is the rounded rectangle (defined by corners ).
Author: mapdigit