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 to you to introduce, in the Android development in the use of some of the image resources, the specific contents of the trouble please seriously check the official website. Here is 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
good. 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 normal image resource is just a picture. You do not need to define your 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 of the Witch Company. http://www.teamtopgame.com/. 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 with the <bitmap> tag. There are very many properties under this tag, 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 to use. Set the tiling mode to repeat:



Nine-patch Use of image resources (important). 9 pictures The cliché is, do not use this tool for Android development that is too much to say just go, we are in the application development. Always need to process the picture, in order to make the picture is stretched without distortion and distortion, so that the edge of the picture to transition more smoothly and naturally.

This is what the Draw9patch.bat tool does.

D:\software\adt-bundle-windows-x86_64-20131030\sdk\tools
under the Tools folder in the SDK, there are a variety of Android-powered gadgets that kids can learn to use. The use of this tool is not explained here, 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:orientation=" 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 image. You cannot use a normal picture. Otherwise, it will be an error.


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 are easy to understand. Similar to the framelayout, we know that the frame layout is covered with one layer above the other. 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 is about these kinds of image resources. Next blog continue to introduce, do not want to let you eat a fat man.



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

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.