0

私はこれと同じトピックについて多くの質問を見て、

android:adjustViewBounds="true"
android:scaleType="fitCenter"

それでも私の画像はそのまま表示されます。

android:scaleType = "fitCenter"

しかし、 fitXYドキュメントによると、これはアスペクト比を維持していません。では、コードを変更して期待どおりに機能させるにはどうすればよいですか?

<?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"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/card"
        android:layout_marginTop="25dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/card" >

        <ImageView
            android:id="@+id/idImage"
            android:layout_width="fill_parent"
            android:layout_height="110dp"
            android:layout_margin="10dp"
            android:adjustViewBounds="true"
            android:scaleType="fitCenter"
            android:src="@drawable/783454" />

    </LinearLayout>

</LinearLayout>

![ここに画像の説明を入力してください] [1]![ここに画像の説明を入力してください] [2] iamがコンセプトを見逃しているのはどこですか?

4

1 に答える 1

0

このコードを見てください。これが、画面に適切に収まるようにビットマップをスケーリングする方法です。多分それはあなたの仕事に関してあなたに役立つそしてあなたにアイデアを与えるでしょう。

private void loadImage() {
    ImageView imageView = (ImageView)findViewById(R.id.imageView);

    Bitmap imageBitmap = ... load original image bitmap;  

    Bitmap scaledBitmap = imageBitmap; 

    // Scaling

    int imgSrcHeight = imageBitmap.getHeight();
    int imgSrcWidth = imageBitmap.getWidth();

    int scaledHeight = 0;
    int scaledWidth = 0;

    int ctnrHeight = imageView.getMeasuredHeight();
    int ctnrWidth = imageView.getMeasuredWidth();

    int mHeight = imgSrcHeight - ctnrHeight;
    int mWidth = imgSrcWidth - ctnrWidth;

    if(mHeight > 0 && mWidth > 0)
    {
        if(mHeight > mWidth)
        {
            // scale to fit height
            if(mHeight > 0)
            {
                scaledHeight = ctnrHeight;

                // if height < 0 it means it's already inside of content
                int coefOverhight = (ctnrHeight * 100)/imgSrcHeight;
                scaledWidth = (int)(imgSrcWidth * ((coefOverhight)/100.0)); 
            }
        }
        else
        {
            // scale to fit width
            if(mWidth > 0)
            {
                scaledWidth = ctnrWidth;
                int coefOverwidth = (ctnrWidth * 100)/imgSrcWidth;
                scaledHeight = (int)(imgSrcHeight * ((coefOverwidth)/100.0));
            }
        }
    }
    else
    {
        scaledHeight = imgSrcHeight;
        scaledWidth = imgSrcWidth;
    }

    scaledBitmap = Bitmap.createScaledBitmap(imageBitmap, scaledWidth, scaledHeight, true);


    imageView.setImageBitmap(scaledBitmap);

}

于 2012-07-30T16:32:02.883 に答える