2

AndroidのURLから画像を取得し、に設定しようとしていますImageView。私がしていることは次のとおりです。

image = new ImageView(mContext);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(MY_WIDTH, MY_HEIGHT);
params.leftMargin = lefMargin;
params.topMargin = topMargin;
image.setImageBitmap(BitmapFactory.decodeStream((InputStream)new URL(MY_URL).getContent());
relativeLayout.addView(image, params);

しかし、画像は私のサイズ(MY_WIDTH、MY_HEIGHT)に適合していません。それは、独自のサイズで表示されます。何をすべきか?

4

3 に答える 3

5

これを試しましたか?

Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(MY_URL).getContent();
Bitmap bitmapScaled = Bitmap.createScaledBitmap(bitmap, MY_WIDTH, MY_HEIGHT, true);
Drawable drawable = new BitmapDrawable(bitmapScaled);
image.setBackgroundDrawable(drawable);
于 2012-06-29T06:28:43.597 に答える
3

この行を ur imageview に追加します

imageview.setScaleType(ImageView.ScaleType.FIT_XY);
imageview.setAdjustViewBounds(true);
于 2012-06-29T06:20:01.480 に答える
0

これは試してみるとうまくいくかもしれませんが、

image = new ImageView(mContext);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(MY_WIDTH, MY_HEIGHT);
params.leftMargin = lefMargin;
params.topMargin = topMargin;
image.setLayoutParams(params );
image.setImageBitmap(BitmapFactory.decodeStream((InputStream)new URL(MY_URL).getContent());
relativeLayout.addView(image);
于 2012-06-29T06:26:14.330 に答える