來源:https://blog.csdn.net/qq_31370269/article/details/50752211
在xml中的drawable/目錄下可以創(chuàng)建Bitmap資源,這樣可以將一張圖片直接轉換成bitmap,并給它設置一些屬性,它指向一個BitmapDrawable對象。
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"] />
常用的9個屬性:
屬性
src 在這里引用圖片資源
antialias 開啟或關閉抗鋸齒
dither 開啟或關閉圖像抖動。當使用圖片的dpi和屏幕不匹配時,開啟圖像抖動可以獲得更好的顯示效果
filter 開啟或關閉濾鏡。當需要對圖片進行縮放操作時,開啟濾鏡可以使圖片更加平滑
tiltMode 貼圖模式。詳細見下文。該屬性與gravity是互斥的。
gravity 重心。詳細見下文。該屬性與tileMode是互斥的。
tint 設置著色。有種蓋一個色層在圖片上的感覺。
tintMode 設置著色模式。詳細見下文。
mipMap 是否將圖片標記為mipmap,使用mipmap能夠提高顯示性能,默認為false
android:tileMode屬性
值 效果
clamp 當圖片>容器時,圖片多余的部分會被截去;當圖片<容器時,會復制圖片的邊緣部分填充空白
disable 圖片會根據(jù)容器大小進行縮放。這是默認值
repeat 圖片會重復填充滿容器。但是當圖片>容器時,多余部分會被截去
mirror 圖片會以鏡像重復的形式填滿容器。同樣,當圖片>容器時,多余部分會被截去
android:gravity屬性
當圖片<容器時,重心決定了它在容器中的位置。
重心有以下幾種:
top 頂部
bottom 底部
left 左邊
right 右邊
center 中心
center_vertical 垂直中心
center_horizontal 水平中心
fill 充滿容器,和tileMode=”disable”是一個效果
fill_vertical 充滿垂直方向
fill_horizontal 充滿水平方向
clip_vertical (不懂,求大神解答)
clip_horizontal (不懂,求大神解答)
android:tintMode屬性
著色模式有以下幾種:
src_in
src_over
src_atop 以上幾種全把圖片給遮住了,看不出有什么差別。求指導!
mutiply 著色與透明度相結合,相當于在圖片上蓋了一層不是很深的顏色
screen 同上,但是顏色會更淺