ListView

时间:2017-02-04 06:18:34

标签: java android android-studio

我有一个长字符串,必须使用项目符号在TextView中表示。但是在每一行之后我都无法创造一些空间。

我得到的是:

*文字是.............. .......................... ...... ....... ............. ................ .............. .... ................. .................... ......... .................. .................................................. ...........................

*另一条线............................................ ..... ................. .................... ........ ................... ............................... ..............................................

*另一条线............................................ ..... ................. .................... ........ ................... ............................... .................................................. ................................

我想要的是,

  • 案文是.............. .......................... ............ ............. ................ ......... ......... ................. .................... .... ....................... .................................................. ...........................

  • 另一条线.......................................... ....... ................. .................... ...... ..................... ............................. ................................................

  • 另一条线.......................................... ....... ................. .................... ...... ..................... ............................. .................................................. ..................................

    子弹后应有适当的缩进,并应使用单一文本视图。

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法获取项目符号字符串:

public static CharSequence makeBulletList(int leadingMargin, CharSequence... lines) {
        SpannableStringBuilder sb = new SpannableStringBuilder();
        for (int i = 0; i < lines.length; i++) {
            CharSequence line = lines[i] + (i < lines.length-1 ? "\n" : "");
            Spannable spannable = new SpannableString(line);
            spannable.setSpan(new BulletSpan(leadingMargin), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            sb.append(spannable);
        }
        return sb;
    }

您也可以修改此方法以将数组列表作为输入。