BackgroundColorSpan with extra vertical indentation

In my application, I have something similar in appearance to shortcuts in the GMail application interface. For those who may not know, they look like this (these shortcuts are shortcuts): Gmail screenshot

To achieve a similar effect, I use draw-draw of nine patches - for each label I create a TextView and assign it the ability to draw. This is a simple solution, but I don't like it. It is not elegant, it is rather slow, as shown by the profiler, and I just don't think this is the right way to do this.

I redesigned the user interface to make it more "ICS-y", so I removed the rounded corners from the shortcuts. And I thought how to replace the 9-patch solution. The most obvious is to use BackgroundColorSpan. But he has one, small flaw. I want my labels to have some kind of addition. With the help of the drawings, this was easy to achieve. With spans it is more difficult. To make the horizontal fill, I can simply add spaces at the beginning and end of the line. But how to increase vertical filling? To clarify the situation, this is a screenshot of the label with BackgroundColorSpan:

enter image description here

I want to make the colored parts above and below the text larger. I think I should use some MetricAffectingSpan, but I could not figure out which one. Or maybe I should write my own? Or, finally, maybe the gaps are simply not able to satisfy my needs, and I have to stay with the images or create a canvas and manually draw everything, as in the GMail application?

+7
source share
1 answer

The easiest way to do this, and I'm sure the GMAIL application uses it, is with forms.

Just create a custom shape , in your case a rectangular shape with rounded corners and a solid color, and assign it to draw, then the background property of your text.

The form is defined in xml. You assign it as follows:

<TextView ... android:background="@drawable/my_awesome_shape" /> 
+2
source

All Articles