android bitmap xml,XML Bitmap
8種機(jī)械鍵盤軸體對(duì)比
本人程序員,要買一個(gè)寫代碼的鍵盤,請(qǐng)問紅軸和茶軸怎么選?
目錄:
定義
一個(gè)XML bitmap是一個(gè)在XML文件中定義的指向一個(gè)bitmap文件的資源。其效果是作為一個(gè)原始位圖文件的別名,并且可以指定一些額外的屬性。
注意:你可以在節(jié)點(diǎn)中使用作為它的子節(jié)點(diǎn)。比如,當(dāng)你定義一個(gè)state list或者layer list的時(shí)候,可以包括一個(gè)android:drawable屬性
Note: You can use a element as a child of anelement. Forexample, when creating astate list orlayer list,you can exclude the android:drawableattribute from anelement and nest ainside it that defines the drawable item.
文件位置:
res/drawable/filename.xml
filename作為資源的ID
編譯資源類型
指向BitmapDrawable類型的指針
資源引用
In Java: R.drawable.filename
In XML: @[package:]drawable/filename
語法:1
2
3
4
5
6
7
8
9
10
11
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"] />
節(jié)點(diǎn)介紹:
定義位圖的來源和屬性
屬性:xmlns:android類型:String。定義了XML的命名空間,必須是”http://schemas.android.com/apk/res/android"。如果是根元素,那么他是必須的,如果是嵌套在里面,那么就不是必須的。
android:src類型:Drawable resource。必需。 引用一個(gè)drawableresource.
android:antialias類型:Boolean。是否開啟抗鋸齒。
android:dither類型:Boolean。如果位圖與屏幕的像素配置不同時(shí),是否允許抖動(dòng).(例如:一個(gè)位圖的像素設(shè)置是 ARGB 8888,但屏幕的設(shè)置是RGB 565)
android:filter類型:Boolean。是否允許對(duì)位圖進(jìn)行濾波。對(duì)位圖進(jìn)行收縮或者延展使用濾波可以獲得平滑的外觀效果。
android:gravity類型:關(guān)鍵字。定義位圖的重力(gravity),如果位圖小于其容器,使用重力指明在何處繪制
必需是下面的屬性,多個(gè)之間用 | 分隔ValueDescriptiontopPut the object at the top of its container, not changing its size.
bottomPut the object at the bottom of its container, not changing its size.
leftPut the object at the left edge of its container, not changing its size.
rightPut the object at the right edge of its container, not changing its size.
center_verticalPlace object in the vertical center of its container, not changing its size
fill_verticalGrow the vertical size of the object if needed so it completely fills its container.
center_horizontalPlace object in the horizontal center of its container, not changing its size.
fill_horizontalGrow the horizontal size of the object if needed so it completely fills its container.
centerPlace the object in the center of its container in both the vertical and horizontal axis, notchanging its size.
fillGrow the horizontal and vertical size of the object if needed so it completely fills itscontainer. This is the default.
clip_verticalAdditional option that can be set to have the top and/or bottom edges of the child clipped toits container’s bounds. The clip is based on the vertical gravity: a top gravity clips thebottom edge, a bottom gravity clips the top edge, and neither clips both edges.
clip_horizontalAdditional option that can be set to have the left and/or right edges of the child clipped toits container’s bounds. The clip is based on the horizontal gravity: a left gravity clipsthe right edge, a right gravity clips the left edge, and neither clips both edges.
android:tileMode類型:Keyword。
定義了tile模式。當(dāng)tile模式被啟用,位圖是重復(fù)的,并且gravity屬性將被忽略。
必須是下列之一常量值:ValueDescriptiondisabledDo not tile the bitmap. This is the default value.
clampReplicates the edge color if the shader draws outside of its original bounds
repeatRepeats the shader’s image horizontally and vertically.
mirrorRepeats the shader’s image horizontally and vertically, alternating mirror images so thatadjacent images always seam.
示例:
1
2
3
4
5
android:src="@drawable/icon"
android:tileMode="repeat" />
參考:
BitmapDrawable
Creatingalias resources
其他
BitmapDrawable的使用
一個(gè)BitmapDrawable就是封裝了一個(gè)位圖。直接以文件的方式,就是封裝了一個(gè)原始的位圖。以Xml方式,可以對(duì)原始的位圖進(jìn)行一系列的處理,比如說抗鋸齒,拉伸,對(duì)齊等等。
要了解BitmapDrawable的使用,還需要明白Bitmap、BitmapFactory等類。Bitmap代表了一個(gè)原始的位圖,并且可以對(duì)位圖進(jìn)行一系列的變換操作。BitmapFactory提供一系列的方法用于產(chǎn)生一個(gè)Bitmap對(duì)象。多用在Canvas中。
關(guān)于繪圖和位圖變換以后再學(xué)習(xí)。BitmapDrawable的使用比較簡(jiǎn)單,就是在其他的xml文件中直接引用就可以了,不過要注意在xml中定義BitmapDrawable各個(gè)屬性使用和含義。
總結(jié)
以上是生活随笔為你收集整理的android bitmap xml,XML Bitmap的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android word转html标签,
- 下一篇: VB.NET 教程_02_常见对象