1

ロード時にアセット イメージを拡大するのに問題があります。BitmapDrawable(Resources, BitmapDrawable) への新しい呼び出しは、1.6 SDK では使用できません。BitmapDrawable を古い方法でロードしてから、何らかの方法で操作する回避策はありますか? setTargetDensity() を無駄に呼び出してみました。私のコード(適切にスケーリングされない)は次のとおりです。

    ImageView iv = (ImageView)view.findViewById(R.id.image);
 iv.setImageDrawable(new BitmapDrawable(view.getContext().getAssets().open(path)));
4

1 に答える 1

5

古き良きRTFMを行った後、うまくいく方法を見つけました。次のコードが機能します。

  ImageView iv = (ImageView)view.findViewById(R.id.image);
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inScaled = true;
    opts.inDensity = DisplayMetrics.DENSITY_MEDIUM;
    Rect padding = new Rect();
    opts.inTargetDensity = view.getResources().getDisplayMetrics().densityDpi;
    Bitmap bm = BitmapFactory.decodeStream(view.getContext().getAssets().open(path), padding, opts);
    iv.setImageBitmap(bm);

背景については、http://d.android.com/guide/practices/screens_support.htmlを参照してください

于 2010-03-31T16:58:21.777 に答える