Monday, September 19, 2011

[android-developers] I'm struggling to understand differences between View.setBackground( NinePatchDrawable) and View.setBackground( BitmapDrawable) differ. As one produces drawing errors while the other does not.

I have an activity with a grid of 3x4 ImageButtons. When an
ImageButton is pressed it grows to fill the screen then shrinks back
down to its original location and size. However _during_ the shrink
animation trailing lines are left and are only cleared once the
animation has finished. I posted about this a while ago: http://goo.gl/eRnmx

I have been able to come up with a few work arounds that have solved
my problem, but I'd really like to understand why some the problem was
occurring in the first place.

I noticed that the problem didn't occur when I used the default
Android ImageButton background. I began to suspect that something
about the solid white background set using:

ImageButton.setBackgroundColor( int c) was causing the problem.

After messing around with a various different backgrounds and setting
them in a number of different ways I came up with a few scenarios that
would both produce the error and not produce the error.

What I found is that if I set the background of the ImageButton using:

ImageButton.setBackgroundColor( Color c)
ImageButton.setBackgroundResource( int res) where res was a normal
png file

the lines would appear during the animation. However when I set te
background using

ImageButton.setBackgroundResource( int res) where the res was a 9
Patch file the problem went away.

I spent an hour or so reading ImageButton.java, View.java, and other
android source files and didn't see any obvious differences about the
way that a NinePatch is set as a background vs a other types of
drawables.

Can someone explain to me what is different about the way the those
two types are drawables are set as a background, so I can continue my
hunt for the bug.

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

No comments:

Post a Comment