Android 画布与图像
我有一个白色半透明的背景图像。它用作文本容器,以便您可以区分背景图像和文本。
目前我使用的图像是带有圆角的白色矩形,但是当然,当在不同的屏幕尺寸上使用它时,图像会扭曲,但不是很大或很明显,但是用画布绘制这个图像会更好或可能吗?
如果可能的话,它会大大减慢应用程序的速度吗?
更新:
谢谢@jkhouw1 我已经研究了 9 个补丁图像,这似乎非常合适。我仍然有兴趣了解画布相对于图像的好处,但如果您发布一些内容作为答案,我会接受它。谢谢。
I have a background image that is white and semi-transparent. This is used as a text container so you can differentiate between the background image and text.
Currently I am using an image that is a white rectangle with rounded corners, but of course when using this on different screen sizes the image is distorted, not massively or that noticeably, but would it be better or possible to draw this image with a canvas?
If it is possible would it slow down the app considerably?
UPDATE:
Thank you @jkhouw1 I have looked into 9 patch images and this seems very suitable. I am still interested in knowing the benefit of canvas against images, but if you post something as an answer I will accept it. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用九个补丁是android可以适当缩放的图形。请参阅此处: http://developer.android.com/guide/developing/tools/ draw9patch.html
和此处 http ://www.higherpass.com/Android/Tutorials/Android-9-Patch-Scaled-Png-Image-Guide/
use a nine patch is a graphic that android can scale appropriately. see here: http://developer.android.com/guide/developing/tools/draw9patch.html
and here http://www.higherpass.com/Android/Tutorials/Android-9-Patch-Scaled-Png-Image-Guide/
还没有尝试过,但我认为通过定义
Haven't tried this yet, but I think this should be possible by defining a shape drawable. You can define round corners and you can make it semi-transparent by defining the color with alpha-value, for example #80FF0000 should be semi-transparent red.
I assume this would be a good solution both in terms of compatibility and performance.