进来给分了。Android中setCompoundDrawablesWithIntrinsicBounds问题。

zhoudianlong 2011-09-19 04:55:54
现在做一个程序但是调用setCompoundDrawablesWithIntrinsicBounds函数显示的图片大小不同。调用setCompoundDrawablesWithIntrinsicBounds(drawable left ,drawable top, drawable right, drawable bottom)显示的大小不对。但是调用setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom)这个重构的函数时显示的大小正确。请问这两个函数区别在那里,怎么把drawable的方法转换成int的方法。急求答案,谢谢!!


RadioButton rb = (RadioButton) getLayoutInflater().inflate(R.layout.radio_button, null);
rb.setCompoundDrawablesWithIntrinsicBounds(null,drawable,null, null);
rb.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.zhuye1, 0, 0);
...全文
1270 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueflo 2012-11-10
  • 打赏
  • 举报
回复
setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) { final Resources resources = getContext().getResources(); setCompoundDrawablesWithIntrinsicBounds(left != 0 ? resources.getDrawable(left) : null, top != 0 ? resources.getDrawable(top) : null, right != 0 ? resources.getDrawable(right) : null, bottom != 0 ? resources.getDrawable(bottom) : null); } 应该没有区别,看上面的源码就知道,整型参数的方法还是调用了drawable参数的那个方法,里面还是根据resID获取到了drawable。 可能你传进去的drawable大小就不对。
yangrunzhi2009 2011-10-20
  • 打赏
  • 举报
回复
drawable的方法转换成int的方法?? drawable不就是通过int代表的资源图片才或得的吗?为什么要去转换?int的在资源文件里面找就可以。

这个是android源代码里面google search的代码:
Drawable googlePlaceholder = getContext().getResources().getDrawabl(R.drawable.placeholder_google);
zhoudianlong 2011-09-20
  • 打赏
  • 举报
回复
进来就给分了。就40分。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧