zoukankan      html  css  js  c++  java
  • 【原创】如何在Android中为TextView动态设置drawableLeft等

    如何在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);

    作者:Nodin
    出处:http://www.cnblogs.com/monodin
    个人博客网站:http://www.coderself.com
    关于作者:爱摄影,爱旅行,爱自由,爱生活,更要爱自己。活在当下,也在为未来打拼!
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。

  • 相关阅读:
    C系统,操作符和词法元素
    值类型和引用类型
    WPF
    C#版本进化
    快速排序
    C语言字符串
    查找
    简单快速排序
    PHP运行出现Notice : Use of undefined constant 的解决办法
    vs2010 修改注释模板
  • 原文地址:https://www.cnblogs.com/monodin/p/3908293.html
Copyright © 2011-2022 走看看