`

Android Drawable总结

阅读更多

Drawable有几种

1:Bitmap

       支持格式:.png (preferred), .jpg (acceptable), .gif (discouraged).

将Bitmap文件放在drawable文件夹下会被AAPT自动优化

2:XML Bitmap

       An XML bitmap is a resource defined in XML that points to a bitmap file. 

       The effect is an alias for a raw bitmap file

       <?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:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />

    Defines the tile mode. When the tile mode is enabled, the bitmap is repeated. 

    Gravity is ignored when the tile mode is enabled.

3:Nine-Patch

     You typically assign this type of image as the background of a View 

     that has at least one dimension set to "wrap_content", 

     and when the View grows to accomodate the content,

     the Nine-Patch image is also scaled to match the size of the View

4:XML Nine-Patch

     An XML Nine-Patch is a resource defined in XML that points to a Nine-Patch file.

     The XML can specify dithering for the image

     <?xml version="1.0" encoding="utf-8"?>

<nine-patch

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:src="@[package:]drawable/drawable_resource"

    android:dither=["true" | "false"] />  图片与屏幕像素不一样的时候,会拉伸?

5:Layer List

    A LayerDrawable is a drawable object that manages an array of other drawables.

    <layer-list

    xmlns:android="http://schemas.android.com/apk/res/android" >

    <item

        android:drawable="@[package:]drawable/drawable_resource"

        android:id="@[+][package:]id/resource_name"

        android:top="dimension"

        android:right="dimension"

        android:bottom="dimension"

        android:left="dimension" ></item>

    </layer-list>

    <item></item>标签里可以利用<bitmap/>标签装载图片,此时图片将不会被拉伸。

    <item>

        <bitmap android:src="@drawable/image"

             android:gravity="center" />

    </item>

6:State List

    不同状态显示不同的图片 常用于背景

    During each state change, the state list is traversed top to bottom and the first item 

    that matches the current state is used—the selection is not based on the "best match," 

    but simply the first item that meets the minimum criteria of the state.

    <?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"

          android:drawable="@drawable/button_pressed" /> <!-- pressed -->

    <item android:state_focused="true"

          android:drawable="@drawable/button_focused" /> <!-- focused -->

    <item android:state_hovered="true"

          android:drawable="@drawable/button_focused" /> <!-- hovered -->

    <item android:drawable="@drawable/button_normal" /> <!-- default -->

</selector>

7:Level List 有什么用

     A Drawable that manages a number of alternate Drawables, each assigned a maximum numerical value.

     Setting the level value of the drawable with setLevel() loads the drawable resource in the level list 

     that has a android:maxLevel value greater than or equal to the value passed to the method.

      <level-list xmlns:android="http://schemas.android.com/apk/res/android" >

          <item

              android:drawable="@drawable/status_off"

              android:maxLevel="0" />

          <item

              android:drawable="@drawable/status_on"

              android:maxLevel="1" />

       </level-list>

8:Transition Drawable  可以让两张图片同时淡入淡出(也只能包含两张图片)

      <?xml version="1.0" encoding="utf-8"?>

         <transition xmlns:android="http://schemas.android.com/apk/res/android">

            <item android:drawable="@drawable/on" />

            <item android:drawable="@drawable/off" />

         </transition>

9:Inset Drawable

    A drawable defined in XML that insets another drawable by a specified distance. 

   This is useful when a View needs a background that is smaller than the View's actual bounds.

   <inset xmlns:android="http://schemas.android.com/apk/res/android"

    android:drawable="@drawable/background"

    android:insetTop="10dp"

    android:insetLeft="10dp" />

10:Clip Drawable 把原图的长,宽,厚度都分成10000level,以此切割

    <?xml version="1.0" encoding="utf-8"?>

         <clip xmlns:android="http://schemas.android.com/apk/res/android"

    android:drawable="@drawable/android"

    android:clipOrientation="horizontal"

    android:gravity="left" /> 

    ImageView imageview = (ImageView) findViewById(R.id.image);

    ClipDrawable drawable = (ClipDrawable) imageview.getDrawable();

    drawable.setLevel(drawable.getLevel() + 1000);

    Increasing the level reduces the amount of clipping and slowly reveals the image.

11:Scale Drawable

     A drawable defined in XML that changes the size of another drawable based on its current level.

     <?xml version="1.0" encoding="utf-8"?>

<scale xmlns:android="http://schemas.android.com/apk/res/android"

   android:drawable="@drawable/logo"

     android:scaleGravity="center_vertical|center_horizontal"

   android:scaleHeight="80%"

   android:scaleWidth="80%" />

12:Shape Drawable

       <shape

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape=["rectangle" | "oval" | "line" | "ring"] >

    <corners

        android:radius="integer"

        android:topLeftRadius="integer"

        android:topRightRadius="integer"

        android:bottomLeftRadius="integer"

        android:bottomRightRadius="integer" />

    <gradient

        android:angle="integer"    必须是45的倍数,0:从左到右,90:从下到上

        android:centerX="integer"

        android:centerY="integer"

        android:centerColor="integer"

        android:endColor="color"

        android:gradientRadius="integer"     android:type="radial"时有效,  放射状

        android:startColor="color"

        android:type=["linear" | "radial" | "sweep"]

        android:useLevel=["true" | "false"] />

    <padding

        android:left="integer"

        android:top="integer"

        android:right="integer"

        android:bottom="integer" />

    <size                            默认是填满控件

        android:width="integer"

        android:height="integer" />

    <solid

        android:color="color" />

    <stroke

        android:width="integer"

        android:color="color"

        android:dashWidth="integer"     跟下面一个属性配套,要一起设置才有效

        android:dashGap="integer" />

</shape>

 

    若要有不清楚的,请查看官方文档:http://developer.android.com/guide/topics/resources/drawable-resource.html

分享到:
评论

相关推荐

    浅谈Android中Drawable使用知识总结

    本篇文章主要介绍了浅谈Android中Drawable使用知识总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    Android高效压缩图片不失真的方法总结

    详情请移步:http://blog.csdn.net/alfred_c/article/details/50542741

    android Bitmap用法总结

    android Bitmap用法总结 Bitmap用法总结 1、Drawable → Bitmap public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable....

    Android画图学习.pdf

    • Android画图学习总结(三)——Drawable • Android画图学习总结(四)——Animation(上) • Android画图学习总结(四)——Animation(中) • Android画图学习总结(四)——Animation(下) • Android...

    自己平时做的android相关的总结

    声明:这些内容是逐步总结过来的,所以可能有当时的理解不正确,只希望大家能做个参考: 内容如下: 目录 一句话总结汇总: Copy project into workspace 和add project into work set 的含义 数字签名总结 JNI ...

    Android切圆角的几种常见方式总结

    Android 中有哪些可以切圆角的实现方式呢? 本文总结一下常用的方式。 以下内容分为以下几部分: 利用 Drawable 的 shape xml 实现 CardView 实现圆角 fresco 中的 SimpleDraweeView 实现圆角 利用 View 的 ...

    Android代码-Android-Animation-Set

    文章开篇总结性文章:《Android 一共有多少种动画?准确告诉你!》 Ⅰ. View Animation / 视图动画 English explanation can go to read this article Ⅱ. Drawable Animation / 帧动画 / Frame 动画 English ...

    android图片处理总结

    1. android 图像处理系列之一--Bitmap、Drawable 和byte[]之间的相互转换..................................................2 2. android 图像处理系列之二--图片旋转、缩放、反转...........................

    android 帧动画,补间动画,属性动画的简单总结

    帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果。... &lt;item android:drawable=@drawable/img1 android:duration=100/&gt; &lt;item android:drawable=@drawable/img2 android:duration=100/&gt; &lt;item

    Android画图学习

    • Android画图学习总结(三)——Drawable • Android画图学习总结(四)——Animation(上) • Android画图学习总结(四)——Animation(中) • Android画图学习总结(四)——Animation(下) • Android...

    Android编程根据系列图片绘制动画实例总结

    本文实例讲述了Android编程根据系列图片绘制动画的方法。分享给大家供大家参考,具体如下: ... &lt;item android:drawable=@drawable/a android:duration=100&gt; &lt;item android:drawable=@drawable/b

    Android移动开发实验4.doc

    《Android应用开发 》实验报告 实验序号:04 实验项目名称:微信朋友圈布局页面 "学 号" "姓 名" "专业、班 " " "实验地点" "指导教师" "实验时间 " " "实验目的及要求 " "1、熟悉Eclipse集成开发的步骤;......

    Android 设置颜色的方法总结

    Android 设置颜色的方法总结 Android中有几种设置界面背景及文字颜色的方法,下面由浅入深分别介绍Android中设置颜色的几种方法: 1.直接在布局文件中设置: android:backgound=#FFFFFFFF, android:textcolor=#...

    Android的TextView使用Html来处理图片显示、字体样式、超链接等

    这段时间在做一个短信项目,需要实现短信中插入表情的功能,本一位非常困难,经过一段时间的研究,发现还是比较簡単的,现在总结如下。 以短信输入框为例,短信的输入框是一个EditText,它的append方法不仅可以...

    Android Studio进行APP图标更改的两种方式总结

    将你准备好的 图标放入res目录下的drawable,在AndroidManifest.xml文件中,找到android:icon以及android:roundIcon这两个属性,设置为你放入的图标文件。 如图,appicon就是我准备替换的文件。注意保存时,保存...

    基于Android中获取资源的id和url方法总结

    下面小编就为大家分享一篇基于Android中获取资源的id和url方法总结,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

    Android LayerDrawable使用实例

    1.在Android项目开发的时候,经常看到很漂亮的UI界面,比如,当你点击一张图片被选中的时候,覆上一张透明的图片。表示被选中,区别与那些没有被选中的。这种是如何实现的呢?答案是LayerDrawable的使用出现的效果。...

Global site tag (gtag.js) - Google Analytics