Android ApiDemos example resolution (64): Graphics-& gt; Drawable-& gt; G

Source: Internet
Author: User

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
 

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.