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);
  • 相关阅读:
    ZOJ
    CodeForces
    模板
    前门
    错误记录
    2021/1/10例会 academy of management journal 2014vol 57 No.2,484-514
    Day7下
    Day7上
    Day6 下(
    Day6上 括号匹配专项
  • 原文地址:https://www.cnblogs.com/yhws/p/3913562.html
Copyright © 2011-2022 走看看