刚学习android不久,打算工作之余做个小应用
本次实现目标:点击应用图标后,全屏显示一张图片,然后初始化应用程序
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// 去掉标题栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// 去掉信息栏
// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.premain);
// 获取屏幕的分辨率
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
String str = "分辨率" + screenWidth + "*" + screenHeight;
Toast.makeText(this, str, Toast.LENGTH_LONG).show();
imageView = (ImageView) findViewById(R.id.preMainImg);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.koala);
// BitmapDrawable bd = new BitmapDrawable(bitmap);
// bd.setTileModeXY(TileMode.CLAMP , TileMode.CLAMP );
// bd.setDither(true);
// imageView.setBackgroundDrawable(bd);
// 获取这个图片的宽和高
int imgWidth = bitmap.getWidth();
int imgHeight = bitmap.getHeight();
// 计算缩放率,新尺寸除原始尺寸
float scaleWidth = ((float) screenWidth) / imgWidth;
float scaleHeight = ((float) screenHeight) / imgHeight;
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
// 旋转图片 动作
// matrix.postRotate(45);
// 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, imgWidth,
imgHeight, matrix, true);
BitmapDrawable bd = new BitmapDrawable(resizedBitmap);
bd.setTileModeXY(TileMode.CLAMP, TileMode.CLAMP);
bd.setDither(true);
imageView.setBackgroundDrawable(bd);
}