내가 가지고있는 활동 확장하는 클래스의에서 onCreate 방법의 코드 조각 다음 : 나는 그것을 실행하면 이미지가 화면에 나타납니다문제 이미지 뷰
ImageView view = (ImageView) findViewById(R.id.ImageView01);
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.sample_landscape, bmpFactoryOptions);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Log.v("IMAGEVIEWERMATRIX", "Display Width: " + display.getWidth());
Log.v("IMAGEVIEWERMATRIX", "Display Height: " + display.getHeight());
Log.v("IMAGEVIEWERMATRIX", "BMP Width: " + bmpFactoryOptions.outWidth);
Log.v("IMAGEVIEWERMATRIX", "BMP Height: " + bmpFactoryOptions.outHeight);
if (bmpFactoryOptions.outWidth > width || bmpFactoryOptions.outHeight > height) {
float heightRatio = (float) height/(float) bmpFactoryOptions.outHeight;
float widthRatio = (float) width/(float) bmpFactoryOptions.outWidth;
// WHY
heightRatio = heightRatio/1.5f;
widthRatio = widthRatio/1.5f;
Log.v("IMAGEVIEWERMATRIX", "heightRatio:" + heightRatio);
Log.v("IMAGEVIEWERMATRIX", "widthRatio: " + widthRatio);
float scale = widthRatio;
if (heightRatio < widthRatio) {
scale = heightRatio;
}
matrix.setScale(scale, scale);
Log.v("IMAGEVIEWERMATRIX", "Scale: " + scale);
} else {
Log.v("IMAGEVIEWERMATRIX", "NOTNOTNOT");
matrix.setTranslate(1f, 1f);
}
Bitmap realBmp = BitmapFactory.decodeResource(getResources(),
R.drawable.sample_landscape);
view.setImageBitmap(realBmp);
view.setImageMatrix(matrix);
제대로 맞게 조정 . 내 문제는 올바른 것으로하기 위해 1.5로 척도를 조정해야한다는 것입니다.
heightRatio = heightRatio/1.5f;
widthRatio = widthRatio/1.5f;
내 직감이 장치의 표시 밀도를 함께 할 수 있다는 것입니다하지만 내 인생, 내가이 작업을 수행해야하는 이유 주위에 내 머리를 정리하고 수 없습니다. 여기
는 레이아웃 XML입니다 :<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/ImageView01" android:scaleType="matrix" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>