Multiple alignment in TextView?

前端 未结 3 910
清酒与你
清酒与你 2020-12-03 03:13

I have a TextView like below. I used this code to set gray color for a part of the text.

// Prepare result text.
final String resultText = text + \"\\n\\n\"          


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-03 03:54

    Though its really late to answer, I assume that it might help someone at least. Add this to your code.

    styledResultText.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE), 
    text.length() + 2, text.length() + 2 + dictionaryName.length(), 
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    

    Alignment.ALIGN_OPPOSITE is the equivalent for right side.

    Alignment.ALIGN_NORMAL is the equivalent for left side.

    Note: This only works when there is at least 1 new-line character (\n) between the left & right-aligned text.

提交回复
热议问题