使用圆角绘制对象 [英] Using a rounded corners drawable

查看:150
本文介绍了使用圆角绘制对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个好贴由受欢迎的谷歌开发者罗曼盖伊演示了如何使用圆角绘制的(称为StreamDrawable中的他的code )上有效的景色。

There is a nice post made by the popular Google developer Romain Guy that shows how to use a rounded corners drawable (called "StreamDrawable" in his code ) on a view efficiently.

样品本身的作品非常好我的银河S3时,在纵向模式,但我有几个问题是:

The sample itself works very well on my Galaxy S3 when in portrait mode, but I have a few issues with it:

  1. 如果屏幕小(例如在QVGA屏幕),则显示的图像得到裁剪。

  1. if the screen is small (for example on qvga screens), the shown images get cropped.

如果我有一个输入位太小比我多希望表现出来,输出的图像有其​​边缘涂抹。即使在银河S3,当你运行示例code和它的景观,它看起来可怕的:

if I have an input bitmap that is too small than how I wish to show it, the output image has its edges smeared. Even on the Galaxy S3, when you run the sample code and it's on landscape, it looks awful:

我仍然不知道它(因为我用的缩放图像的使用示例code的解决方法),但它认为,即使这个解决方案是一个有点慢,当在使用列表显示。也许有这个一个renderscript解决方案?

I'm still not sure about it (since I use a workaround of scaling the image for using the sample code), but it think that even this solution is a bit slow when being used in a listView. Maybe there is a renderscript solution for this?

没关系,如果我使用setImageDrawable或setBackgroundDrawable。它必须是一些在绘制本身。

It doesn't matter if I use setImageDrawable or setBackgroundDrawable. It must be something in the drawable itself.

我试着变量和bitmapShader玩,但是毫无效果。可悲的是<一href="http://developer.android.com/reference/android/graphics/Shader.TileMode.html">TileMode不具有值只是拉伸图像,只平铺以某种方式

I've tried to play with the variables and the bitmapShader, but nothing worked. Sadly TileMode doesn't have a value for just stretching the image, only tiling it in some way.

作为一种变通方法,我可以创造一个新的缩放的位图,但它只是一种解决方法。当然还有一个更好的方法也不会比它应该使用更多的内存。

As a workaround I can create a new scaled bitmap, but it's just a workaround. Surely there is a better way which will also not use more memory than it should.

如何解决这些问题,并使用这个伟大的code?

How do I fix those issues and use this great code?

推荐答案

我认为解决方案是psented上的 本网站 效果很好。

I think that the solution that is presented on this website works well.

不像其他的解决方案,它不会导致内存泄漏,即使它是基于罗曼盖伊的解决方案。

unlike other solutions, it doesn't cause memory leaks, even though it is based on Romain Guy's solution.

编辑:现在支持库,你也可以使用<一个href="https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawable.html"相对=nofollow> RoundedBitmapDrawable (使用<一个href="https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawableFactory.html"相对=nofollow> RoundedBitmapDrawableFactory )。

now on the support library, you can also use RoundedBitmapDrawable (using RoundedBitmapDrawableFactory ) .

这篇关于使用圆角绘制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆