Make a certain part of a android-textview align to the right

前端 未结 6 1460
南旧
南旧 2020-12-04 20:37

I have this TextView. Some parts of it is supposed to be aligned to the left and some parts to the right. How would I do this in Java?

Basicly I want t

6条回答
  •  感情败类
    2020-12-04 21:00

    TextView resultTextView = new TextView(this);
    final String resultText = LeftText + "  " + RightText;
    final SpannableString styledResultText = new SpannableString(resultText);
    styledResultText.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE)
        , LeftText.length() + 2
        , LeftText.length() + 2 + RightText.length()
        , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    resultTextView.setText(styledResultText);
    

    Alignment.ALIGN_OPPOSITE is the equivalent for right side.

    Alignment.ALIGN_NORMAL is the equivalent for left side.

提交回复
热议问题