Thursday, August 27, 2015

[Android][Resolved] android make ImageView fit screen width

Add this line before you use your ImageView.
imgview.setScaleType(ScaleType.FIT_XY);

Example:
File wallpaperFile = new File(targetDir + "/wallpaper.jpg");
Uri wallpaperDir = Uri.fromFile(wallpaperFile);
ImageView testView = (ImageView) findViewById(R.id.testView);
Bitmap wallpaperBitmap = BitmapLoader.loadBitmap(wallpaperDir.getEncodedPath(), 200, 200);
testView.setScaleType(ImageView.ScaleType.FIT_XY);
testView.setImageBitmap(wallpaperBitmap);

Reference:
http://stackoverflow.com/questions/4668001/android-stretch-image-in-imageview-to-fit-screen

No comments :

Post a Comment