在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
2016-05-12 17:33
561 查看
在代码中如果要修改drawableRight设置的图片可以使用API
void android.widget.TextView.setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
Drawable可以通过 Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new); 得到。
但是API提示,setCompoundDrawables() 调用的时候,Drawable对象必须调用setBounds(int left, int top, int right, int bottom)方法,于是我们加一行代码就可以了。
[html] view plain copy
rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
整体代码如下:
[html] view plain copy
Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new);
rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
tvVersionStatus.setCompoundDrawables(null, null, rightDrawable, null);
void android.widget.TextView.setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
Drawable可以通过 Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new); 得到。
但是API提示,setCompoundDrawables() 调用的时候,Drawable对象必须调用setBounds(int left, int top, int right, int bottom)方法,于是我们加一行代码就可以了。
[html] view plain copy
rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
整体代码如下:
[html] view plain copy
Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new);
rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
tvVersionStatus.setCompoundDrawables(null, null, rightDrawable, null);
相关文章推荐
- C# 后台请求web服务方法
- Java 1.5并发包之一:Lock
- zkfc报错:java.net.NoRouteToHostException: No route to host
- java中的常见异常及错误和处理方法
- python中lock和rlock(递归锁)的区别
- JAVA字符串格式化-String.format()的使用
- java的继承关系中对象的加载和初始化顺序
- springmvc+easyui Ajax提交返回json IE出现下载问题
- java中日期时间格式与毫秒数的转换如何将指定时间转换为Date类型
- vb()
- File类使用详解
- 电阻TP在系统休眠唤醒后无法使用的一点小问题
- Java 基本数据类型的取值范围。
- Java类的加载和初始化
- 《JAVA继承与多态》改写程序清单10-6中的Course类,编写一个测试类测试所有的方法
- 单片机C语言开发学习笔记---动态的数码管
- java编程经验积累
- python socket编程
- 深入理解Java:注解(Annotation)自定义注解入门
- JNA参数传递问题,Java数组