2012-12-30 4 views
-2

나중에 임의의 크기의 이미지가 포함될 이미지 뷰가 있습니다 이미지 뷰를 이미지로 채우고 싶지만 그 비율을 유지하려면 입니다. 따라서 크기 조정 유형 인 FITXY 또는 centercrop 내 이미지의 일부가 자르기 때문에)임의의 크기의 이미지를 ImageView에 맞 춥니 다

어떻게하면됩니까? 이 테스트 코드에서

, 나는 매트릭스 내 화면의 높이/폭 해결 왼쪽과 내 이미지

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 


    > 

    <ImageView 
     android:id="@+id/imgTest" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 

     android:src="@drawable/test" 
     /> 

답변

0

의 오른쪽에 공백이

private Bitmap resize(Bitmap bm, int w, int h) 
    { 
     int width = bm.getWidth(); 
     int height = bm.getHeight(); 
     int newWidth = w; 
     int newHeight = h; 
     float scaleWidth = ((float) newWidth)/width; 
     float scaleHeight = ((float) newHeight)/height; 

     Matrix matrix = new Matrix(); 
     matrix.postScale(scaleWidth, scaleHeight); 
     Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); 

     return resizedBitmap; 
    } 
0

이것을 시도하십시오 :

<ImageView 
    android:id="@+id/imgTest" 
    android:layout_width="wrap_content" 
    android:layout_height="100dp" 
    android:layout_alignParentLeft="true" 
    android:paddingRight="20dp" 
    android:scaleType="fitStart" 
    android:src="@drawable/test"/> 
+0

몇 마디 f 설명이 좋았을거야. – Najzero

관련 문제