How to render smooth Gradients with Android

SneWs's picture

If you're like me, you've probably noticed that when making gradients with Android, they might get rendered badly, it's not as smooth as it can be, especially when using the emulator.

To get nice and smooth gradients, you just need to add one line of code to you're Activity.

// Call this in you're onCreate() for ex.
getWindow().setFormat(PixelFormat.RGBA_8888);

The above code snippet will enable a much better and smoother look of you're gradient(s). But please be advised that this isn't a silver bullet, the downside is the following.

You're app will consume twice as much RAM, and rendering will be much much slower if it's not hardware accelerated.

3 comments

by Alireza behrooz on Sun, 12/25/2011 - 23:31

Hey man!
I was looking for some gradient examples in google! I was skimming the google result previews very fast to find an example with sample images. When I was looking at this page, I recognized you! Now my gradients are smoother :))
Thanks!

SneWs's picture

by SneWs on Mon, 12/26/2011 - 16:35

I will def. keep the hat =)
Happy hacking!

by povipobi1986 on Wed, 03/27/2013 - 08:12

Эхх, я всегда думал, что можно сделать нормально, если думать головой

Post new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
© 2008 - 2012 Marcus Grenängen. Drupal theme by Kiwi Themes.