3

editText の背景を「setBackgroundResource」で設定すると、すべて正常に動作します。同じ画像で「setBackgroundDrawable」を使用すると、引き伸ばされてしまいます...

左が「setBackgroundResource」、右が「setBackgroundDrawable」の結果:

http://i.stack.imgur.com/yQi5n.jpg (申し訳ありませんが、ここに画像を投稿することは許可されていません...)

コード :

View chips = EditChipsActivity.this.findViewById(mydID);
chips.setBackgroundResource(R.drawable.chips_filter);

対:

View chips = EditChipsActivity.this.findViewById(mydID);
Bitmap bkg = ((BitmapDrawable) getResources().getDrawable(R.drawable.chips_filter)).getBitmap();
BitmapDrawable bkg = new BitmapDrawable(bkg);
chips.setBackgroundDrawable(bkg);

(背景に描画したいので、独自のビットマップを作成して setBackgroundDrawable を使用する必要があります)

4

1 に答える 1

1

これを試して:

View chips = (EditText) findViewById(R.id.editText1);
    Bitmap bkg = ((BitmapDrawable) getResources().getDrawable(R.drawable.chips_filter)).getBitmap();
    BitmapDrawable bkgbt = new BitmapDrawable(getResources(),bkg);
    chips.setBackgroundDrawable((Drawable) bkgbt);

そしてあなたのEditText:

<EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </EditText>

これがあなたが望むことをするなら、私はそうではありません....

于 2012-04-15T13:20:44.277 に答える