Showing posts from March, 2014

Snippet: align a TextView around an image

A few weeks ago I discovered the Spans on Android,after reading the wonderful post by Flavien Laurent . In this post I will describe how to realize a particular layout not very common on Android: a text around an image. This layout is not an Android Pattern, but it can be useful in same cases. As always it is just an example, and you should improve some points in your real project. Use a simple layout: To achieve our scope, we can use a LeadingMarginSpan.LeadingMarginSpan2 . This span allows the implementor to specify the number of lines of text to which this object is attached that the "first line of paragraph" margin width will be applied to. /** * */ class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 { private int margin; private int lines; MyLeadingMarginSpan2(int lines, int margin) { this.margin = margin; th