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:
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Linearlayout Android: Id = "@ + ID/framelayout01"
- Android: Background = "@ drawable/layout_background" Android: layout_width = "fill_parent"
- Android: layout_height = "wrap_content" xmlns: Android = "http://schemas.android.com/apk/res/android">
- <Textview Android: text = "welcome to use this software" Android: Id = "@ + ID/textview01"
- Android: textcolor = "# f0f0f0" Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"> </textview>
- </Linearlayout>
Copy code
This is the public layout file I defined. I named it title.
Then we use the following layout file:
- <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:
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Shape xmlns: Android = "http://schemas.android.com/apk/res/android">
- <Gradient Android: startcolor = "#52 adcd" Android: endcolor = "#1c87b1"
- Android: angle = "270.0" type = "parmname" text = "parmname">
- </Gradient>
- </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.