1

のテキストの下に画像をドロップするにはどうすればよいですかTextView。たとえば、パンの画像をパンのテキストの下にドロップしたいとしますTextView。TextViewのテキストの一部に、背景色ではなく描画可能な色を表示したいのですが。ImageSpanで可能ですか?

4

3 に答える 3

1

android:drawablebottom="@drawable/bread"テキストビューに追加するだけです

透かしのようにしたい場合は、次のように ImageButton を使用します。必ず小さなアイコンのような画像を使用してください。

<ImageButton
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:src="@drawable/bread" /> 
于 2012-12-19T05:58:22.100 に答える
1

xml の TextView にandroid:drawablebottom="@drawable/yourimage"を追加するだけです

またはそれ以外の場合、Java で同等のものは次のとおりです。

public void setCompoundDrawablesWithIntrinsicBounds (Drawable left, Drawable top, Drawable right, Drawable bottom)

利用方法:

myText.setCompoundDrawablesWithIntrinsicBounds(null,null,null, myNewDrawable);
于 2012-12-19T06:02:04.423 に答える
0

以下のコードを書いて試してみてください

XML ファイル内

<Button
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:src="Bread" android:id="@+id/mBtn1" />

あなたのJavaファイルで。

Button mBtn1 = (Button) findViewById(R.id.mBtn1);
Drawable d = getResources().getDrawable(R.drawable.bread);
mBtn1.setCompoundDrawablesWithIntrinsicBounds(null, null, null, d);

それはあなたの問題を解決します。

于 2012-12-19T06:22:58.393 に答える