一并蝗、使用ImageView 的src 和background
src :原圖大小牲迫,不被拉伸;
background:為Imageview的背景,根據(jù)ImageView給長寬進行拉伸借卧;
二、設(shè)置Imageview的透明度
android:src在設(shè)置ImageView的setAlpha(int alpha)時筛峭,起作用;
android:background在設(shè)置ImageView的setAlpha(int alpha)時铐刘,不起作用;
mImageView.setBackgroundDrawable(mDrawable.mutate());
mImageView.getBackground().setAlpha(100);
三、設(shè)置ImageView的前景(foreground)
有時候設(shè)計需要在ImageView 上面覆蓋一層(如灰色)
View 提供了一個setForeground(Drawable foreground)
四影晓、使用ImageView的“android:adjustViewBounds”
如果想設(shè)置圖片固定大小镰吵,又想保持圖片寬高比,需要如下設(shè)置:
- 設(shè)置setAdjustViewBounds為true挂签;
- 設(shè)置maxWidth疤祭、MaxHeight;
- 設(shè)置設(shè)置layout_width和layout_height為wrap_content
五饵婆、正確使用ImageView的“android:scaleType”
ImageView的“android:scaleType”屬性是對src才有效的
ScaleDrawable類是afc框架中提供了一個專門處理Drawable scale的類勺馆,在ImageView的ScaleType的基礎(chǔ)上額外提供了11中裁剪方式:
(1)CROP_CENTER
(2)CROP_START
(3)CROP_END
(4)FIT_CENTER
(5)FIT_START
(6)FIT_END
(7)MATCH_WIDTH_TOP
(8)MATCH_WIDTH_BOTTOM
(9)MATCH_WIDTH_CENTER
(10)CENTER
(11)CROP_BY_PIVOT

image
要保證ScaleDrawable.CROP_START屬性設(shè)置成功,在xml中一定要設(shè)置“android:scaleType=”fitXY”