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

Android 动态设置TextView drawableLeft的方式

时间:2015-02-07 10:23:54      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

对于TextView或者EditText动态设置drawableLeft,drawableRight,drawableTop,drawableBottom,drawableStart,drawableEnd的方法总结


Android中提供了许多动态设置的方法

技术分享

但是用中容易造成的问题是,我们往往只调用了如上的一些方法,但并没有将Drawable的Bounds设置为特定的数据,导致这些图片无法显示,因此,做如下操作即可

设置右方向上的图片

Drawable drawable = getResources().getDrawable(R.drawable.hotel_search);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
selectCityTv.setCompoundDrawables(null, null, drawable, null);

或者我们可以使用另外一些方法

selectCityTv.setCompoundDrawablesWithIntrinsicBounds( Drawable  left, Drawable  top,Drawable  right,Drawable  bottom)

-------这里就不再试验了--------


try doing it

Android 动态设置TextView drawableLeft的方式

标签:

原文地址:http://my.oschina.net/ososchina/blog/376269

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