Alx wrote:
> Hello all,
> 
> I've certainly missed something on how to use ImageView objects but
> I'm lost for now...
> 
> So, I've created 2 ImageView, using the same resource :
> 
>         i0 = new ImageView(this);
>         i0.setAdjustViewBounds(true);
>         i0.setImageResource(R.drawable.blood_01);
>         i0.setLayoutParams(new AbsoluteLayout.LayoutParams
> (99,113,0,0));
>         i0.setAlpha(0);
>         mAbsoluteLayout.addView(i0);
> 
>         i1 = new ImageView(this);
>         i1.setAdjustViewBounds(true);
>         i1.setImageResource(R.drawable.blood_01);
>         i1.setLayoutParams(new AbsoluteLayout.LayoutParams
> (99,113,100,0));
>         i1.setAlpha(0);
>         mAbsoluteLayout.addView(i1);
> 
> First, I set the alpha for both ImageView to 0.
> 
> When touching the screen, I set this alpha to 255 only for i1.
> 
> public boolean  onTouch(View v, MotionEvent event)
>     {
>       switch (event.getAction())
>       {
>               case MotionEvent.ACTION_DOWN:
>               {
>                       i1.setAlpha(255);
>                  }
>                break;
> (...)
> 
> If I do that, both i0 and i1 are displayed (alpha = 255 for both of
> them).
> 
> 
> If I use 2 different resources for i0 and i1 (by duplicating my
> blood_01.png file for instance)
> it does work fine => only i1 is displayed.
> 
> 
> So, it looks like the setAlpha is applied to the resource, and not to
> the ImageView.
> 
> How can I avoid that?
> I won't duplicate my pictures to work around that.
> 
> Any help appreciated.

http://android-developers.blogspot.com/2009/05/drawable-mutations.html

Or, to cut to the punch line:

Drawable star = context.getResources().getDrawable(R.drawable.star);
if (book.isFavorite()) {
  star.mutate().setAlpha(255); // opaque
} else {
  star.mutate().setAlpha(70); // translucent
}


-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Need help for your Android OSS project? http://wiki.andmob.org/hado

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to