码迷,mamicode.com
首页 > 移动开发 > 详细

如何在Android中为TextView动态设置drawableLeft等

时间:2014-08-14 23:52:06      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:android   blog   strong   div   log   res   ef   on   

如何在Android中为TextView动态设置drawableLeft等

 
两种方式:
 
方式1:手动设置固有边界
1 Drawable drawable = getResources().getDrawable(resId);
2 //注意查看方法TextView.setCompoundDrawables(Drawable, Drawable, Drawable, Drawable)
3 //的注释,要求设置的drawable必须已经通过Drawable.setBounds方法设置过边界参数
4 //所以,此种方式下该行必不可少
5 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
6 setCompoundDrawables(drawable, null, null, null);

 

方式2:自动设置固有边界
1 setCompoundDrawablesWithIntrinsicBounds(resId, 0, 0, 0);
2 //setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(resId), null, null, null);

如何在Android中为TextView动态设置drawableLeft等,布布扣,bubuko.com

如何在Android中为TextView动态设置drawableLeft等

标签:android   blog   strong   div   log   res   ef   on   

原文地址:http://www.cnblogs.com/yhws/p/3913562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!