Issue
In my Android app I am trying to programmatically create multiple color variations of one drawable resource. (I have a unique resource for every letter in a scrabble set, and there are randomly X number of the same letter tiles on the board at a given time)
Right now my Draw method calls the same id over each unique resource:
int id = context.getResources().getIdentifier(this.tileLetter.toString(), "drawable", mypackagename);
Drawable t = context.getResources().getDrawable(id);
t.setAlpha(num);
t.draw(mycanvasname);
My problem is that when I try to call setAlpha on different objects of this same class, the changes are shown on all tiles of the same letter that are on the canvas. (Again, think about trying to change the alpha of just one unique tile 'A' on the board and leaving the other 'A's alone).
UPDATE Calling t.mutate() before t.setAlpha(num) did the trick.
Solution
What if you create clones of the Drawable and modify each as required? See Flavio's answer here: Android: Cloning a drawable in order to make a StateListDrawable with filters
Answered By - Shirish Hirekodi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.