您的位置:首页 > 移动开发 > Android开发

android 让图片充满整个屏幕

2015-06-05 15:29 429 查看
方法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, 0, 0, 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, 0, 0, m.getWidth(), m.getHeight(), matrix, true);        创建一张图片
参数分别是:
图片对象、x、y、w、h、矩阵对象、是否开启抗锯齿

setContentView(FitTheScreenSizeImage(R.drawable.welcomeview,screenWidth,screenHeigh));}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: