How to make the first character much larger than other in a TextView

后端 未结 3 1685
谎友^
谎友^ 2020-12-16 23:51

I would like to display a paragraph of long text as follow. Here is the snapshot from Flipboard.

\"enter

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 00:05

    By using a single TextView with BufferType.SPANNABLE will solve the problem.

    final SpannableString spannableString = new SpannableString(title);
    int position = 0;
    for (int i = 0, ei = title.length(); i < ei; i++) {
        char c = title.charAt(i);
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
            position = i;
            break;
        }
    }
    spannableString.setSpan(new RelativeSizeSpan(2.0f), position, position + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    //titleTextView.setText(spannableString.toString());
    titleTextView.setText(spannableString, BufferType.SPANNABLE);
    

提交回复
热议问题