4 Android development skills

Source: Internet
Author: User

1.AndroidShare the same layout file in XML

I always thought that sharing the same layout file was copied after the previously written layout, or through JavaCodeAdded by layoutinflater. But today we provide a more convenient way to use it. You can use other layout files in any of your layout files. The Code is also very simple, as shown below:

    1. <? XML version = "1.0" encoding = "UTF-8"?>
    2. <Linearlayout Android: Id = "@ + ID/framelayout01"
    3. Android: Background = "@ drawable/layout_background" Android: layout_width = "fill_parent"
    4. Android: layout_height = "wrap_content" xmlns: Android = "http://schemas.android.com/apk/res/android">
    5. <Textview Android: text = "welcome to use this software" Android: Id = "@ + ID/textview01"
    6. Android: textcolor = "# f0f0f0" Android: layout_width = "wrap_content"
    7. Android: layout_height = "wrap_content"> </textview>
    8. </Linearlayout>

Copy code

This is the public layout file I defined. I named it title.

Then we use the following layout file:

    1. <Include layout = "@ layout/Title"/>

Copy code

The title layout can be directly obtained to our current layout file.

Tip: Use the include flag to add layout to our current layout file. You can also use the current view. findviewbyid to obtain any view in the title layout file.


2. Add the gradient effect to the background using XML

To achieve the gradient effect for the background, the most traditional method is to use psto make a gradient, but I am too lazy to learn the PS technology, and I am too lazy to add an image to the application, here we use a great method provided by Google to solve the background gradient function.

First, add an XML file to the drawable folder and write the following code:

    1. <? XML version = "1.0" encoding = "UTF-8"?>
    2. <Shape xmlns: Android = "http://schemas.android.com/apk/res/android">
    3. <Gradient Android: startcolor = "#52 adcd" Android: endcolor = "#1c87b1"
    4. Android: angle = "270.0" type = "parmname" text = "parmname">
    5. </Gradient>
    6. </Shape>

Copy code

The corresponding attributes are relatively simple. We will not introduce them here. Android: Shape = "rectangle" indicates that the gradient shape is a rectangle. Android: angle = "270.0" indicates that the angle is 270. The gradient from top to bottom is changed. If I change to 0, the gradient is changed from left to right, if you change the gradient by 90.0, the gradient will go down from below. You can change the parameters to try the effect.

Send one:
Attachment: 20101020.jpg
Tip: The angle is 0.

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.