Drawable的使用——BitmapDrawable

BitmapDrawable表示的是一張圖片,在實際開發中,直接引用原生的圖片即可,也可以通過xml的方式來描述它,這個時候BitmapDrawable可以設置更多的效果。

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_ice"
    android:antialias="true"
    android:dither="true"
    android:tileModeX="mirror"
    android:tileModeY="repeat"
    android:filter="true"
    android:mipMap="true"
    android:gravity="center"
    android:alpha="2">
</bitmap>

從xml文件中可以看到,bitmap的屬性。

android:src 就是圖片的資源id,
android:dither是否開啓抖動效果,
android:antialias是否開啓抗鋸齒
android:tileMode 平鋪模式(disable, clamp, repeat, mirror,其中disable表示關閉平鋪模式,這個是默認值,當開啓平鋪模式後,gravity屬性會被忽略)
android:filter是否開啓過濾效果
mimMap是一種圖片相關的處理技術,也叫紋理映射,默認爲false
android:gravity圖片位置
android:alpha透明度

如下圖 雪糕的顯示

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章