【发布时间】:2015-01-27 23:00:42
【问题描述】:
我试图使图像适合整个屏幕尺寸。我的活动布局 XML 如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
显示图片的代码:
private void showImage(String imageName){
String directory = "/sdcard/DCIM/cat/" + imageName;
File imageFile = new File(directory);
if(imageFile.exists()){
Bitmap imageBitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
//rotating the bitmap by 90 degree clockwise. Assume the bitmap is 270 degree clockwise.
Matrix mtx = new Matrix();
mtx.preRotate(90);
int w = imageBitmap.getWidth();
int h = imageBitmap.getHeight();
imageBitmap = Bitmap.createBitmap(imageBitmap,0,0,w,h,mtx,false);
imageBitmap = imageBitmap.copy(Bitmap.Config.ARGB_8888,true);
ImageView imageView = (ImageView)findViewById(R.id.imageView1);
imageView.setImageBitmap(imageBitmap);
}
屏幕上的输出如下:
大家可能会观察到,图像的左右两侧都有空格。有什么方法可以让图片完美贴合屏幕?
【问题讨论】:
-
尝试为 ImageView 使用 android:scaleType="fitXY" 属性。
-
谢谢!!!解决了我的问题。 :)