2013年10月8日星期二

[Android] ImageView with getDrawable () to get the Drawable problem

With ImageView with getDrawable () to get the Drawable
and
getBaseContext (). getResources (). getDrawable () to obtain the picture is inconsistent ?
For example, drawable: R.drawable.l, first set ImageView iv.setImageResource (R.drawable.l);
Then iv.getDrawable ()
and
getBaseContext (). getResources (). getDrawable (R.drawable.l)
obtain drawable not equal ?
not equal with == and equals , is how is it ?
------ Solution ---------------------------------------- ----
Why should the same?
two drawable objects.
png images may share the same one , but two drawable should still two objects.
------ eference --------------------------------------- < br> do not add additional flag case, then how can I judge the two are not the same picture ?
------ eference --------------------------------------- < br> landlord of the problem has been resolved ? I also encountered this problem
------ eference ---------------------------------- -----
from sd card read an image file, how to set the path to getDrawable inside or there are other ways to set the path to come
------ eference --- ------------------------------------
landlord big god ? I have also encountered this problem , SOS ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
------ eference ------------------- --------------------
not resolved ah. Later, no look at this issue , there should be other ways to judge is not the same object, such as id values ​​or paths.
------ eference --------------------------------------- < br> after setting iv.setImageResource (R.drawable.l) after , but also with getResources (). getDrawable (R.drawable.l), rather than iv.getDrawable ().
you call getDrawable (R.drawable.l) twice , will get two different objects , because it will get two new ImageDrawable ().
You can use Drawable.getConstantState () to compare them , of course, sometimes being given .
------ eference --------------------------------------- < br> Compare ConstantState objects
similar to:
ConstantState icon = mContext.getResources (). getDrawable (R.drawable._smsmms). getConstantState ();
ConstantState icon2 = imageView.getBackGround (). getConstantState ();

没有评论:

发表评论