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
    关于作者:爱摄影,爱旅行,爱自由,爱生活,更要爱自己。活在当下,也在为未来打拼!
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。

  • 相关阅读:
    hive metastore && hiveserver2 . 基本配置
    Flink HA 搭建坑
    protobuf 编译安装
    编译Hadoop 2.7.2支持压缩 转
    centos 6挂载磁盘
    python
    python之面向对象(一)
    python
    python-文件压缩和解压
    python-configparser模块
  • 原文地址:https://www.cnblogs.com/monodin/p/3908293.html
Copyright © 2011-2022 走看看