首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >调用setCompoundDrawables()不会显示复合可绘制文件

调用setCompoundDrawables()不会显示复合可绘制文件
EN

Stack Overflow用户
提问于 2011-07-06 10:08:02
回答 9查看 84.9K关注 0票数 361

在我调用setCompoundDrawables方法之后,未显示复合可绘制对象。

代码语言:javascript
复制
Drawable myDrawable = getResources().getDrawable(R.drawable.btn);
btn.setCompoundDrawables(myDrawable, null, null, null);

有什么想法吗?

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2011-07-07 00:24:26

票数 681
EN

Stack Overflow用户

发布于 2014-10-19 16:03:05

使用这个(我测试过)。它运行良好

代码语言:javascript
复制
Drawable image = context.getResources().getDrawable( R.drawable.ic_action );
int h = image.getIntrinsicHeight(); 
int w = image.getIntrinsicWidth();   
image.setBounds( 0, 0, w, h );
button.setCompoundDrawables( image, null, null, null );
票数 73
EN

Stack Overflow用户

发布于 2012-02-13 15:20:29

图像为空,因为它没有指定的边界。您可以使用setCompoundDrawables(),但在指定图像的边界之前,请使用Drawable.setBounds()方法

票数 51
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6590838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档