How to add an outer shadow for a rounded-corners drawable?

牧云@^-^@ 提交于 2019-12-11 01:22:39

问题


I'm using this RoundedCorners library (based on Romain Guy's post) which allows to set both outline border and a rounded rectangular image to an imageView .

I need to add an outer shadow (meaning it's outside of the image being shown) to the image that is shown (say ,to direction south-east) . I've decided that since the border is the larger part of what is shown, I would add the shadow to it instead of to the image, using the next extra code in RoundedDrawable :

mBorderPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);

Of course, I've also added the fields and populated them with values.

Problem is, the shadow seem to ignore the dx,dy values i've given it, and it's just setting the background to the entire imageView .

I've read here and some people claim that using setShadowLayer on new android API (from 11+) won't work except on texts because it tries to use the GPU , but I've tested it on API10 too and it had the same result.

How could it be? What should I do in order to fix it or use an alternative?

I assume I could add a new paint like the one used for the border, but this would mean I need to change a lot more code that depends on it too (or actually I need to do it anyway? ) . Plus, i might make it a little uglier than what is shown for real shadows.

来源:https://stackoverflow.com/questions/16383842/how-to-add-an-outer-shadow-for-a-rounded-corners-drawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!