In android, you can customize draw lines, draw circles, draw rectangles, and use custom fonts.

Source: Internet
Author: User

First, create an xml file. The resource type is drawble and the root element is shape.

I. Custom draw lines

<Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "line"> <stroke android: width = "1dp" // line width android: color = "#33 ccff" // color android: dashWidth = "2dp" // line segment length of the dotted line android: dashGap = "5dp"/> // Interval Length of the dotted line </shape>


You can use the textview control in the layout xml file to set the background attributes.


Ii. Custom circle

<Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "oval"> <solid android: color = "#33 ccff"/> <size android: width = "50dp" // circle or elliptical android: height = "50dp"/> </shape>


Use the imageview control in the layout xml file


3. Customize the rectangle

<Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "rectangle"> <gradient android: angle = "45" // an integer multiple of gradient angle 45 android: centerColor = "#00ff00" // gradient color android: endColor = "# 0000ff" android: startColor = "# ff0000"/> <solid android: color = "#33 ccff"/> // solid color <size android: height = "100dp" android: width = "50dp"/> <corners android: radius = "10dp"/> // rounded corner </shape>


4. Use custom Fonts


Copy the font format file. ttf to the assets Directory, read the font file Typeface. createFromAsset, and set the type setTypeface.


The font in the Code is as follows:

TextView textView = (TextView) findViewById (R. id. textView2); Typeface tf = Typeface. createFromAsset (getAssets (), "fonts/samplefont. ttf "); // read the text textView. setTypeface (tf); // set the font


This article is from the "wangcuijing" blog, please be sure to keep this source http://wangcuijing.blog.51cto.com/7233352/1286598

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.