So I'm facing little problem with proper allign strings in my TextView. I have 2 strings (left and right) and TextView that has match_parent width. The point is that every solution I find doesn't worked (or doesn't work as I want).
So some code:
String LeftText = "Left";
String RightText = "Right";
SpannableString finalString = new SpannableString(LeftText+ " " + RightText);
finalString.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), LeftText.length() , LeftText.length() +RightText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(finalString);
I find similar code that works here: solution that works partly but there is new line sing "\n". I noticed that If I replace " " with "\n" "right" String is on the right side of TextView but little lower (becasue of the new line sing) but I want this whole text to be in the same line. Can I do something about this?
If you want to achieve this in a single TextView without splitting it into two, you can try something like this:
The idea is as follows (assuming that the left and right texts do not overlap):