android-own definition of the use of image resources (1)

Source: Internet
Author: User

android-own definition of the use of image resources
April 28, 2014 Monday sunny mood calm
this blog post for you to introduce, in the Android development by the use of some of the image resources, the specific contents 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 the use of demo sample, let children's shoes have a visual understanding of these image resources. code resource: http://download.csdn.net/detail/wwj_748/7263481interested friends can add the group I created, there is a wealth of learning resources OH: 299402133 (mobile development enthusiast 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
Well, the above is the provision of some of the image resources, we can define 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 of the use of these image resources:
use of common image resourcesThe common image resource is simply to apply a picture, do not need to define their own such as the following:/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 using the <bitmap> tag, which has a lot of attributes under it, such as the following:
<?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, set 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 much to say just go, we are in the application of development, at all times need to deal with the picture, in order to make the picture is stretched without distortion and distortion, so that the picture edge part of the 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 folder, 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 the need to learn to participate in 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>
For example, the following:


the use of XML nine-patch image ResourcesThis resource, the wizard did not how to use, the specific use: under the Drawable folder, 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.
used in Layout files:/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>

For example, the following:

use of layer resourceslayer resources very easy to understand, similar to the framelayout, we know that the frame layout is a layer to cover the top, right. Layer resources are also such drops, under the Drawable folder, 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>

For example, the following:

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.



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.