android-Use of custom image resources
April 28, 2014 Monday sunny mood calm
this blog to introduce you, in the Android development often used in some of the image resources, the details of the trouble please seriously check the official website, the following attached a link: http://developer.android.com/guide/ topics/resources/drawable-resource.html, this blog mainly gives use examples, let children's shoes have a visual understanding of these image resources. code resource: http://download.csdn.net/detail/wwj_748/7263481 Interested friends can add the group I created, there is a wealth of learning resources OH:
299402133 (Mobile development Enthusiasts Group)
There are several image resources in Android:
- Common Image Resources
- XML Image Resources
- Nine-patch Image Resources
- XML Nine-patch Image Resources
- Layer Image Resource
- Image status (state) resource
- Image level Resources
- Fade in (transition) resources
- Embedding (Inset) image resources
- Cut (clip) image resources
- Proportional (scale) image resources
- Profile (Shape) image resources
OK, here are some of the image resources provided, we can customize these image resources to provide our programs to use, so that our program more beautiful. The following little witch takes some time to give you a brief introduction to the use of these image resources:
use of common image resourcesordinary image Resources just apply a picture, do not need to define their own as follows:/05_kindofdrawableuse/res/layout/simple_res.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/logo"/></linearlayout>
:that picture is the logo,http://www.teamtopgame.com/of the company, this is the official website, like to play online games of children's shoes this can play a bit.
the use of XML image resourcesThis image resource is used <bitmap> tag, there are many properties under this tag, as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><bitmap xmlns:android= "http://schemas.android.com/apk/res/ Android " android:src=" @[package:]drawable/drawable_resource " android:antialias=[" true "| "false"] android:dither=["true" | "false"] android:filter=["true" | "false"] android:gravity=["Top" | "Bottom" | "Left" | "Right" | "Center_vertical" | " Fill_vertical "| "Center_horizontal" | "Fill_horizontal" | " Center "| "Fill" | "Clip_vertical" | "Clip_horizontal"] android:mipmap=["true" | "false"] android:tilemode=["Disabled" | "Clamp" | "Repeat" | "Mirror"]/>
Here I will not give you a description of what it means, I hope children shoes to see their own official website./05_kindofdrawableuse/res/layout/xml_res.xml
<?xml version= "1.0" encoding= "Utf-8"? ><bitmap xmlns:android= "Http://schemas.android.com/apk/res/android" android:src= "@drawable/logo" android:tilemode= "repeat" ></bitmap>
Here is a picture that sets the tiling mode to repeat:
Nine-patch Use of image resources (important). 9 pictures cliché, do not use this tool for Android development that is too unreasonable, we in the application development, always need to deal with the picture, in order to make the picture is stretched without distortion and distortion, so that the edge of the picture to transition more smooth and natural. This is what the Draw9patch.bat tool does. D:\software\adt-bundle-windows-x86_64-20131030\sdk\tools
in the SDK in the tools directory, there are various tools provided by Android, children's shoes to learn to use it, the use of this tool here, the wizard does not explain, you need to learn to refer to other bloggers write blog, Baidu, Google often accompany you around. /05_kindofdrawableuse/res/layout/ninepatch_res.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:background= "@drawable/res"/> <imageview android:layout_width= "Match_ Parent " android:layout_height=" wrap_content " android:background=" @drawable/res "/> < ImageView android:layout_width= "match_parent" android:layout_height= "Wrap_content" android: background= "@drawable/nine_patch"/></linearlayout>
As follows:
the use of XML nine-patch image ResourcesThis resource, the wizard has not how to use, specific use method: under the Drawable directory, define the following resources/05_kindofdrawableuse/res/drawable/xml_ninepatch.xml
<?xml version= "1.0" encoding= "Utf-8"? ><nine-patch xmlns:android= "http://schemas.android.com/apk/res/ Android " android:dither=" false " android:src=" @drawable/nine_patch "></nine-patch>
The src of this resource is a. 9 picture, can not use ordinary pictures, or will be an error OH.
to use in a layout file:/05_kindofdrawableuse/res/layout/xml_ninepatch_res.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:background= "@drawable/xml_ninepatch"/></linearlayout>
As follows:
use of layer resourceslayer resources are easy to understand, like framelayout, we know that the frame layout is covered in layers, right. Layer resources are also such drops, in the drawable directory, define the following resources:/05_kindofdrawableuse/res/drawable/layers.xml
<?xml version= "1.0" encoding= "Utf-8"? ><layer-list xmlns:android= "http://schemas.android.com/apk/res/ Android > <item> <bitmap android:gravity= "center" android:src= "@drawable/logo"/ > </item> <item android:left= "10DP" android:top= "10DP" > <bitmap android:gravity= "center" android:src= "@drawable/logo"/> </item> <item android: left= "20DP" android:top= "20DP" > <bitmap android:gravity= "center" android:src= "@ Drawable/logo "/> </item></layer-list>
/05_kindofdrawableuse/res/layout/layer_res.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/layers"/></linearlayout>
As follows:
This blog on the introduction of these kinds of image resources, the next blog continue to introduce, do not want to let you eat a fat man.
android-use of custom image resources (1)