是否可以获得多行文本的每一行,因为它将出现在固定宽度的文本视图中,具有字体,大小,对齐而不实际绘制文本视图?
我的文字存储在一个字符串中。我可以为文本应用不同的字体,大小,对齐方式。当它传递给我的api时,我想把它分成一个字符串列表,它是如何在应用程序中显示的。这可能吗?
在视图中,文本使用以下格式进行格式化:
TextView textView = new TextView(getContext());
LayoutParams textLayoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (itemWidth > 0) {
textLayoutParams.width = itemWidth;
}
if (itemHeight == -1) {
textLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
}
textLayoutParams.leftMargin = xPosition;
textLayoutParams.topMargin = yPosition;
textView.setLayoutParams(textLayoutParams);
textView.setPaintFlags(Paint.ANTI_ALIAS_FLAG);
font = getFontName(font);
if (!StringUtils.isEmpty(font)) {
CalligraphyUtils.applyFontToTextView(getContext(), textView, CalligraphyConfig.get(), "fonts/" + font);
}
if (!StringUtils.isEmpty(color))
textView.setTextColor(Color.parseColor(color));
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (int)size );
if (alignment.equalsIgnoreCase("center")) {
textView.setGravity(Gravity.CENTER);
} else if (alignment.equalsIgnoreCase("left")) {
textView.setGravity(Gravity.START);
} else if (alignment.equalsIgnoreCase("right")) {
textView.setGravity(Gravity.END);
} else if (alignment.equalsIgnoreCase("left_center")) {
textView.setGravity(Gravity.START | Gravity.CENTER);
}
addView(textView);
对于多行字符串,它将显示在不同的行上。在后台进程中,我想知道哪一个子串显示在第一行,哪个子串显示在第二行,依此类推。这甚至可能吗?