Question

Please excuse the lack of imagery I'm trying to make my list view pop a little bit. One option i'm experimenting with is to add a gradient to the background of each list row. The gradient has three colors and by default resembles this structure:

-- (Start color)
|
|
-- (Center color)
|
|
-- (End color)

I want it to be more like this:

-- (Start color)
|
-- (Center color)
|
|
-- (Center color)
|
-- (End color)

The difference is that there is more of the center color in the middle and the gradient starts very close to the ends.

Can someone offer me some guidance?

Edit I'm trying to stay away from images as much as possible, though i'm not opposed to trying options with images.

Was it helpful?

Solution

In my best knowledge Android currently does not support a gradient as what you're after. A LinearGradient would give you the closest result, but there is no way to set a 'gravity' on a colour, and the number of colours is limited to three.

That being said, you could easily render out the gradient in your favourite image editing software and transform it into a 9-patch. The area for vertical stretching would then be in the middle of that image. That will make the 'center colour' fill up most of the available height and keep the start and end colours at the top and bottom.

There is a 9-patch tool included in the SDK, that facilitates drawing only in the 1-pixel border and gives a preview of your work in progress. It has it shortcomings though, so I wouldn't blame you for using some other imaging software.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top