Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlignmentSpan not working for RadioButton text

Tags:

android

I'm trying to align to the right a portion of a RadioButton text using the AlignmentSpan class. However it is not working because the text is not aligned as expected.

SpannableStringBuilder builder = new SpannableStringBuilder();

builder.append(option.getLabel());

int start = builder.length() + 1;

builder.append(" ");
builder.append(price);
builder.append("€");

int end = builder.length();

builder.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), start, end,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);

builder.setSpan(bss, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

As you can see from the code I also apply a StyleSpan which works properly.

N.B RadioButton has android:layout_width="match_parent"

like image 780
rciovati Avatar asked Nov 21 '13 16:11

rciovati


2 Answers

Random advice, might work or not, but... Did you try injecting Unicode control characters in the string? (improperly) Using characters such as U+200E, U+200F, U+202A...U+202E you can convince the text renderer that they are parts of RTL mixed with LTR. Not sure if that helps or not, you might need to have stuff in separated paragraphs anyway, but that's the only thing I could think of right now.

like image 159
rock3r Avatar answered Oct 30 '22 13:10

rock3r


Try this once android:layout_width="_wrap_content".

and try this and tell me result....

final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);

builder.setSpan(bss, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    int end = builder.length();

builder.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), start, end,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

If i m not wrong You are overriding the span initially set by you. So try to set the span together.

like image 42
Jatin Malwal Avatar answered Oct 30 '22 11:10

Jatin Malwal