2011-12-19 10 views
4

私はsplash.pngを持っていて、fitXYのように画面上のすべての場所にこの画像が表示されるようにImageViewにしてください。 splash.pngのサイズは480x767です。イメージのサイズを設定するには?

コードで変更する必要があるものは何ですか?

public class BitmapConfigView extends LinearLayout { 
private Bitmap mImage; 
private Paint mPaint = new Paint(); 

public BitmapConfigView(Context context) { 
    super(context); 

    BitmapFactory.Options opts = new BitmapFactory.Options(); 
    opts.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    opts.inScaled = false; 
    mImage = BitmapFactory.decodeResource(getResources(), R.drawable.splash, opts); 

    mPaint.setDither(true); 
    setWillNotDraw(false); 
    setOrientation(VERTICAL); 
    setGravity(Gravity.BOTTOM); 
} 

@Override 
protected void onDraw(Canvas canvas) { 
    canvas.drawBitmap(mImage, 0.0f, 0.0f, mPaint); 
} 
} 
+0

あなたはどのようなアプローチを試みましたか?どのような問題がありましたか? –

+0

私は[リンク](http://stackoverflow.com/questions/8563370/how-to-apply-rgba-8888-and-dither-correctly/8563452#8563452)をさまざまな方法で決定しようとしています。この質問のコードは私に優れたイメージを与えますが、サイズが間違っています。 – Sviatoslav

答えて

1

、私はWebViewを使用:

public class TestwebViewimageActivity extends Activity { 
private WebView wv; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    wv = (WebView) findViewById(R.id.webview); 
    wv.setWebViewClient(new HelloWebViewClient()); 
    wv.setBackgroundColor(0x00000000); 
    wv.getSettings().setBuiltInZoomControls(false); 
    wv.setVerticalScrollBarEnabled(false); 
    wv.setHorizontalScrollBarEnabled(false); 
    wv.loadUrl("file:///android_asset/6.html"); 

} 

private class HelloWebViewClient extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     view.loadUrl(url); 
     return true; 
    } 
} 
} 

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

    <WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 
</LinearLayout> 

6.html

<html> 
<head> 
<style type="text/css"> 

body { 
margin: 0; 
    background-color: black; 
} 

html, body, #my-image { 
    width: 100%; 
    height: 100%; 
} 

#my-image { 
    background-size: cover; 
    background-image: url(splash.png); 
    background-position: center center; 
    background-repeat: no-repeat; 
} 

</style> 
</head> 
<body> 

<div id="my-image"></div> 

</body> 
</html> 
1

これは私が通常スケール法で行う方法です。

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { 

int width = bm.getWidth(); 

int height = bm.getHeight(); 

float scaleWidth = ((float) newWidth)/width; 

float scaleHeight = ((float) newHeight)/height; 

// create a matrix for the manipulation 

Matrix matrix = new Matrix(); 

// resize the bit map 
    matrix.postScale(scaleWidth, scaleHeight); 
// recreate the new Bitmap 

Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); 

return resizedBitmap; 

} 
+2

これはOKですが、android.graphics.Bitmap.createScaledBitmapはあなたのために行います:) –

3

ビットマップをスケールします。これは、あなたが探しているものです。その結果
android.graphics.Bitmap.createScaledBitmap

+0

この場合、bMapScaled = Bitmap.createScaledBitmap(mImage、320,480、false); '画像のグラデーションに歪みがあります: ( – Sviatoslav

+0

)filter = true(4番目の引数)で試してみてください。 –

+0

画像上に作成されたテキストは非常によく見えますが、グラデーションではありません。 機会をそれを見てください。 – Sviatoslav

関連する問題