Android资源文件-drawable整理

转载请附地址:http://blog.csdn.net/a774057695/article/details/49864907

我主要是想整理xml文件的

内容是网上搜集过来的,去掉了一些错误的东西,把这些语法做个备份,有些注解回头再跟上吧。

灵活使用资源文件会使得App的体验感更强,实现也不会让人感到蛋疼

Drawable资源:

特殊说明:

Dither(图像的抖动处理,当每个颜色值以低于8位表示时,对应图像做抖动处理可以实现在可显示颜色总数比较低(比如256色)时还保持较好的显示效果

filter:直译是过滤器,应该是抗锯齿用的。

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.     Insert 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>

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值