I need to have a text view displaying two texts - one of them left aligned, the other - right aligned. After reading about spans, I composed the following code:
private Spannable generateText(PageModel page) {
final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
final String pageNumber = page.getNumber() + " ";
final String string = pageNumber + dateFormat.format(new Date(page.getLastModified())) ;
Spannable spannable = Spannable.Factory.getInstance().newSpannable(string);
spannable.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_NORMAL), 0, pageNumber.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), pageNumber.length() + 1, string.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
Spannable spannable = generateText(page);
textView.setText(spannable);
The result is that both are left(normal) aligned. Actually, no alignment happens at all, even if I use center align. The bounds of string parts do not cross over, why does it not work? Do you have any idea why would this not work?