Android-自己定义图像资源的使用

2014年4月28日 周一 天气晴朗 心情平静
本篇博文给大家介绍一下,在Android开发中经经常使用到的一些图像资源,具体内容麻烦请各位认真查看官网,下面附上一个链接:http://developer.android.com/guide/topics/resources/drawable-resource.html,本篇博客主要给出使用演示样例,让童鞋们对这些图像资源有个直观的了解。
有兴趣的朋友能够加本人创建的群,里面有丰富的学习资源哦:299402133(移动开发狂热者群)
Android中有下面几种图像资源:
  • 普通图像资源
  • XML图像资源
  • Nine-patch图像资源
  • XML Nine-patch图像资源
  • 图层(Layer)图像资源
  • 图像状态(state)资源
  • 图像级别(Level)资源
  • 淡入淡出(transition)资源
  • 嵌入(Inset)图像资源
  • 剪切(Clip)图像资源
  • 比例(Scale)图像资源
  • 外形(Shape)图像资源
好,上面就是提供的一些图像资源了,我们能够自己定义这些图像资源供给我们程序使用,让我们的程序更加好看。下面小巫花点时间逐个给大家介绍一下这些图像资源的用法:

普通图像资源的使用

普通图像资源就仅仅是应用一张图片而已,不须要自己定义例如以下:
/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:orientation="vertical" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo" /> </LinearLayout>

效果图:

那张图片是小巫公司的logo,http://www.teamtopgame.com/,这是官网,喜欢玩网游的童鞋这个能够玩一下。

xml图像资源的使用

这个图像资源是使用<bitmap>标签的,这个标签下有非常多属性,例如以下:
<?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"] />

这里我不会给大家一个个介绍是什么意思,希望童鞋们自己去官网查看。

/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>

这里用到一张图片,设置平铺模式为反复:

Nine-patch 图像资源的使用(重要)

.9图片老生常谈了,做Android开发的没用过这个工具那就太说只是去的,我们在应用开发其中,时刻须要对图片进行处理,为了让图片被拉伸的时候不会变形和扭曲,让图片边缘部分过渡得更加平滑自然。这就是draw9patch.bat这个工具的作用。
D:\software\adt-bundle-windows-x86_64-20131030\sdk\tools
在SDK中的tools文件夹下,就有Android提供的各种工具,童鞋们自己学着去使用吧,这个工具的使用这里小巫就不解说了,须要学习的能够參考其它博主写的博文,百度、Google常伴你左右。
/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>

效果图例如以下:

XML Nine-Patch 图像资源的使用

这个资源,小巫没怎么用过,具体用法:
在drawable文件夹下,定义下面资源
/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>
这个资源的src是一张.9图片,不能使用普通的图片,不然会报错的哦。
在布局文件里使用:
/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:orientation="vertical" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/xml_ninepatch" /> </LinearLayout>

效果图例如以下:

图层资源的使用

图层资源非常easy理解,就相似FrameLayout,我们知道帧布局都是一层一层往上覆盖的,对吧。图层资源也是这样子滴,在drawable文件夹下,定义下面资源:
/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:orientation="vertical" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/layers" /> </LinearLayout>

效果图例如以下:

本篇博客就介绍这几种图像资源,下篇博客继续介绍,不想让各位一口吃掉一个胖子。

Android-自己定义图像资源的使用(1)的更多相关文章

  1. Android资源之图像资源(图层图像资源)

    曾经看别人的程序的drawable目录里有xml资源,说实话第一次见到这种xml图像资源时,我真心不知道是干什么的.抽出时间学习了一下图像资源.才了解了这类图像资源的妙用. 以下我来分享一下这部分知识 ...

  2. Android-用你自己的自定义图像资源(2)

    Android-自己定义图像资源的使用 2014年4月29日   上一篇博客.介绍前面几种图像资源的使用,本篇博客把剩下的所有介绍完: 普通图像资源 XML图像资源 Nine-patch图像资源 XM ...

  3. Android资源之图像资源(图像级别资源)

    图像状态资源仅仅能定义有限的几种状态. 假设须要很多其它的状态,就要使用图像级别资源. 在该资源文件里能够定义随意多个图像级别. 每一个图像级别是一个整数区间,能够通过ImageView.setIma ...

  4. Android自己定义控件——3D画廊和图像矩阵

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/39932689 1.3D画廊的实现 我们知道android系统已经为我们提供好了一个 ...

  5. Android资源之图像资源(状态图像资源)

    在上一篇博文中.我主要解说了XML图像资源中的图层资源,在此图像资源博文中我会给大家陆续解说XMl图像资源的图像状态资源.图像级别资源.淡入淡出资源.嵌入图像资源.剪切图像资源和外形资源. 1.图像状 ...

  6. Android自己定义控件而且使其能够在xml中自己定义属性

    为什么要自己定义View android开发中自己定义View的优点是显而易见的.比方说以下的这个顶部导航,它被设计出如今应用的每一个界面,但每次的内容却不尽同样.我们不能在每一个layout资源中都 ...

  7. Android开发 ---如何操作资源目录中的资源文件2

    Android开发 ---如何操作资源目录中的资源文件2 一.颜色资源管理 效果图: 描述: 1.改变字体的背景颜色 2.改变字体颜色 3.改变按钮颜色 4.图像颜色切换 操作描述: 点击(1)中的颜 ...

  8. Android <Android应用开发实战> 资源类型<一>

    1.字符串资源>>1.普通字符串>>2.字符串数组 <resources> <string-array name="planets_array&qu ...

  9. android学习笔记32——资源

    Android应用资源 资源分类: 1.无法直接访问的原生资源,保存于asset目录下 2.可通过R资源清单类访问的资源,保存于res目录下 资源的类型以及存储方式 android要求在res目录下用 ...

随机推荐

  1. phpcms v9使用GET调用指定id文章内容、页面数据方法

    不知道大家有没有相同的体会?在使用Phpcms V9建站调用数据的时候,基础的数据用默认的模板的调用语句就好了,但复杂不常见的数据怎么调用呢?我们技术可能会研究半天,怀着探索的精神不断尝试.孜孜不倦. ...

  2. SuperSocket与Netty之实现protobuf协议,包括服务端和客户端

    今天准备给大家介绍一个c#服务器框架(SuperSocket)和一个c#客户端框架(SuperSocket.ClientEngine).这两个框架的作者是园区里面的江大渔. 首先感谢他的无私开源贡献. ...

  3. ios开发之C语言第一天

    最近在学习ios开发,先学习C语言,再学习OC和swift.正所谓"万丈高楼平地起",打好基础是很重要的,所以C语言也必须好好学习.学习中所使用的操作系统是OS X,开发工具是Xc ...

  4. Junit4拓展工具JCategory与Testng的Group功能比较

    前言 笔者前段时间分享过一遍文章,关于如何通过引入新注解来扩展Junit4,以解决Process上的问题: JUnit扩展:引入新注解Annotation 最近在跟外面的同事聊的时候,得知Testng ...

  5. Lua function 函数

    Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...

  6. 【HDOJ】1518 Square

    DFS+剪枝.与HDOJ 1455如出一辙. #include <stdio.h> #include <stdlib.h> #include <string.h> ...

  7. 【响应式Web设计实践 #BOOK#】

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. unity3d ppsspp模拟器中的post processing shader在unity中使用

    这个位置可以看到ppsspp的特殊处理文件位置来看看这些特效 用来测试的未加特效图片 ppsspp: 传说系列一生爱---英杰传说 最后的战士 aacolor 是关于饱和度,亮度,对比度,色调的调节, ...

  9. HDOJ/HDU 2535 Vote(排序、)

    Problem Description 美国大选是按各州的投票结果来确定最终的结果的,如果得到超过一半的州的支持就可以当选,而每个州的投票结果又是由该州选民投票产生的,如果某个州超过一半的选民支持希拉 ...

  10. Android学习笔记(五)Fragment简介

    Fragment是在Android 3.0 (API level 11)中引入的Activity的子模块.初衷是为了适应大屏幕的平板电脑,我们只需要使用Fragment对UI组件进行分组.模块化管理, ...