方法1:
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/lbhao" /> 以上是代码:只需加入在ImageView中加入这个代码即可android:scaleType="fitXY"
方法2:
public static Bitmap FitTheScreenSizeImage(Bitmap m,int ScreenWidth, int ScreenHeight)
{
float width = (float)ScreenWidth/m.getWidth();
float height = (float)ScreenHeight/m.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(width,height);
return Bitmap.createBitmap(m, , , m.getWidth(), m.getHeight(), matrix, true);
}
float width = (float)ScreenWidth/m.getWidth(); 屏宽/图宽
float height = (float)ScreenHeight/m.getHeight(); 屏高/图高
Matrix matrix = new Matrix(); 矩阵对象
matrix.postScale(width,height); 把缩放系数传入该对象中
return Bitmap.createBitmap(m, , , m.getWidth(), m.getHeight(), matrix, true); 创建一张图片
参数分别是:
图片对象、x、y、w、h、矩阵对象、是否开启抗锯齿 setContentView(FitTheScreenSizeImage(R.drawable.welcomeview,screenWidth,screenHeigh));}