zoukankan      html  css  js  c++  java
  • TextView的setCompoundDrawables不显示问题解决

    TextView的setCompoundDrawables不显示问题解决

     
     
     

      TextView可以用过调用setCompoundDrawables设置一张图片出现在上下左右四个地方。代码如下:

      Drawable drawable = getResources().getDrawable(R.drawable.img);
            drawable.setBounds(0, 0, 32, 32);
            textView.setCompoundDrawables(drawable, null, null, null);

      注意到这个Drawables必须已经调用过了setBounds。如果不设置则无法显示。

    项目中的代码:

    public static void setTextDrawableRight(Context context, TextView tv, int id) {
    Drawable drawable = context.getResources().getDrawable(id);
    if (drawable != null) {
    drawable.setBounds(0, 0, Units.dip2px(12f), Units.dip2px(6f));
    }
    tv.setCompoundDrawables(null, null, drawable, null);
    }
  • 相关阅读:
    QuartzQuartz定时任务
    jdbc模糊查询、分页查询、联合查询
    PreparedStatement
    web服务器简述
    JDBC基本操作
    RMI
    Http编程
    2020毕业季业务开发宝典
    程序设计流程图
    系统概要框图
  • 原文地址:https://www.cnblogs.com/fightzhao/p/4755885.html
Copyright © 2011-2022 走看看