-1

後でランダムなサイズの画像を含む画像ビューがあります。画像ビューに画像を入力しますが、比率は維持します(したがって、画像の一部がトリミングされるため、スケールタイプFITXYまたはセンタークロップは使用しないでください)

これどうやってするの ?

このテストコードでは、画像の左右に空白があります

    <?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"
      />

4

2 に答える 2

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;
    }
于 2013-01-06T22:46:11.077 に答える
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"/>
于 2013-02-27T14:19:54.050 に答える