【发布时间】:2015-03-07 07:22:27
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageview"
android:scaleType="centerCrop"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/imagecancel"
android:layout_marginBottom="10dp"
android:background="#80000000">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/imagecaption"
android:hint="Enter a description"
android:textColorHint="#80ffffff"
android:textColor="#ffffff"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"/>
</RelativeLayout>
<ImageButton
android:contentDescription="@string/imagecancel"
android:id="@+id/imagecancel"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:scaleType="fitStart"
android:background="@android:color/transparent"
android:src="@drawable/cancel"/>
<ImageButton
android:contentDescription="@string/imagesave"
android:id="@+id/imagesave"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:scaleType="fitEnd"
android:background="@android:color/transparent"
android:src="@drawable/ok"/>
</RelativeLayout>
Java
private void previewCapturedImage() {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
ExifInterface exif = null;
int orientation = 0;//Since API Level 5
try {
exif = new ExifInterface(fileUri.getPath());
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
} catch (IOException e) {
e.printStackTrace();
}
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
Log.i("file path",exifOrientation);
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath());
previewimage.setImageBitmap(bitmap);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
Log.i("RotateBitmap","270");
RotateBitmap(bitmap, 270);
previewimage.setRotation(270);
break;
case ExifInterface.ORIENTATION_ROTATE_90:
Log.i("RotateBitmap","90");
RotateBitmap(bitmap, 90);
previewimage.setRotation(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Log.i("RotateBitmap","180");
RotateBitmap(bitmap, 180);
previewimage.setRotation(180);
break;
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
public static Bitmap RotateBitmap(Bitmap source, float angle)
{
Matrix matrix = new Matrix();
matrix.postRotate(angle);
previewimage.setImageBitmap(source);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
这里的图像填充在小屏幕手机中正常。但在大屏幕手机图像显示不正确。它显示距离顶部 2 厘米和底部 2 厘米的间隙。图片来自手机摄像头拍照。我想全屏填充图像。如何解决这个问题。
【问题讨论】:
-
在你的图像视图中使用 android:scaleType="fitXY"
标签: android android-layout android-camera