1

如何将图像放在TextView. 例如,我想在. 我真的想为 TextView 中的部分文本显示可绘制而不是背景颜色。ImageSpan 可以吗?TextView

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

您可以简单地将android:drawablebottom="@drawable/yourimage"添加到 xml 中的 TextView

或者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 回答