android - Expanding a ViewGroup's surface to include text shadows -
in android project, using framelayout
contain textview
. textview
has large shadow on (to provide glow). however, android detecting textview
's bounding rect of contained text, without shadow, , result compositor gets confused when objects animate around it.
as workaround tried forcing textview
have own hardware surface (with setlayertype
), closely cropped text , doesn't account shadow, shadow gets cut off.
i have tried adding padding framelayout
, doesn't expand surface - moves textview
down , right padding amount.
if set background color on framelayout
, surface expand cover entire size, unfortunately background visible, if set 0x01000000
. if there way force contain entire background if background color 0, suitable solution.
what easiest way expand hardware surface include text glow, ideally without affecting position of text itself?
the trick canvas
believe every pixel has been touched, without having paint. drawing colordrawable
not work, because every step along way seems detect fully-transparent color doesn't need rendered. and, apparently render text shadow rendering canvas thinks it's been invalidated – so, example, drawing couple of background pixels expand surface still not cause actual text shadow rendered.
however, there operation cause canvas
's clipping mask updated transparent pixels – transparent bitmap
!
so, adding background drawable
renders out transparent bitmap
has desired effect. can add transparent bitmap resource (drawn using bitmapdrawable
), or can this:
final bitmap bmp = bitmap.createbitmap(2, 2, bitmap.config.alpha_8); final paint bmppaint = new paint(); wrappingframelayout.setbackground(new drawable() { public int getopacity() { return pixelformat.translucent; } public void draw(final canvas c) { c.drawbitmap(bmp, null, getbounds(), bmppaint); } public void setalpha(final int a) {} public void setcolorfilter(final colorfilter cf) {} });
Comments
Post a Comment