【问题标题】:imageView get Drawable use getDrawble()imageView 获取 Drawable 使用 getDrawble()
【发布时间】:2012-11-06 01:40:33
【问题描述】:

ImageView如何使用getDrawable()获取Drawable?为什么它与使用 getBaseContext().getResources().getDrawable() 获取图像不同? 喜欢drawable:R.drawable.l,先设置ImageView iv.setImageResource(R.drawable.l);然后使用 iv.getDrawable() 和 getBaseContext().getResources().getDrawable(R.drawable.l)。但是为什么它会得到不同的drawable?使用“==”或equals,是不对的。感谢您的建议。

【问题讨论】:

    标签: android


    【解决方案1】:

    iv.setImageResource(R.drawable.l) 也会使用 getResources().getDrawable(R.drawable.l),

    你调用 getDrawable(R.drawable.l) 两次,两次会得到两个不同的对象

    新的 ImageDrawable()。

    您可以使用 Drawable.getConstantState() 来比较它们。但它有时也会失败。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      相关资源
      最近更新 更多