TextView的setCompoundDrawables设置后图片不显示,如何解决?

2026-06-09 10:081阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计162个文字,预计阅读时间需要1分钟。

TextView的setCompoundDrawables设置后图片不显示,如何解决?

TextView 可通过调用 setCompoundDrawables 设置图片出现在上下左右四个方位。代码示例如下:

Drawable drawable=getResources().getDrawable(R.drawable.delete_circle);drawable.setBounds(0, 0, 32, 32); // drawable.setBo... 省略

// 使用 setCompoundDrawables 设置图片位置textView.setCompoundDrawables(drawable, null, null, null);


TextView可以用过调用setCompoundDrawables设置一张图片出现在上下左右四个地方。代码如下:

Drawable drawable = getResources().getDrawable(R.drawable.delete_circle);

//drawable.setBounds(0, 0, 32, 32);
drawable.setBounds(0, 0, mDeleteIcon.getMinimumWidth(), mDeleteIcon.getMinimumHeight());

//设置需要现实的位置 , 不需要显示的 直接填null 即可
textView.setCompoundDrawables(drawable, null, null, null);

注意 : 到这个Drawables必须已经调用过了setBounds。如果不设置则无法显示。

阅读全文

本文共计162个文字,预计阅读时间需要1分钟。

TextView的setCompoundDrawables设置后图片不显示,如何解决?

TextView 可通过调用 setCompoundDrawables 设置图片出现在上下左右四个方位。代码示例如下:

Drawable drawable=getResources().getDrawable(R.drawable.delete_circle);drawable.setBounds(0, 0, 32, 32); // drawable.setBo... 省略

// 使用 setCompoundDrawables 设置图片位置textView.setCompoundDrawables(drawable, null, null, null);


TextView可以用过调用setCompoundDrawables设置一张图片出现在上下左右四个地方。代码如下:

Drawable drawable = getResources().getDrawable(R.drawable.delete_circle);

//drawable.setBounds(0, 0, 32, 32);
drawable.setBounds(0, 0, mDeleteIcon.getMinimumWidth(), mDeleteIcon.getMinimumHeight());

//设置需要现实的位置 , 不需要显示的 直接填null 即可
textView.setCompoundDrawables(drawable, null, null, null);

注意 : 到这个Drawables必须已经调用过了setBounds。如果不设置则无法显示。

阅读全文