假设我有两个textviews
,一个标题和详细信息,详细信息是 toEndOf 标题(同一行),而标题是一行,详细信息,可以是多个,我的问题是,如何配置详细信息textview
,当它开始一个新行时,而不是将其与textview
的上一行对齐,将其与标题{{1}对齐因此创建一个段落感觉。
请参阅这些屏幕截图,了解我要完成的工作(标题是粗体文字,详细说明其余部分):
到目前为止我有什么:
我能想到的唯一解决方案是为两者使用一个textview
,并使用HTML格式化文本,但如果我需要更大的文字大小,该怎么办?
谢谢!
答案 0 :(得分:0)
答案 1 :(得分:0)
使用SpannableText解决您的问题以分隔两个文字视图。
答案 2 :(得分:0)
您可以使用SpannableText
这将完成这项工作!
<TextView
..
android:id="@+id/text_view"
/>
...
TextView text=(TextView)findViewById(R.id.text_view);
String head = "Seat (s):";
String body = " The baby name means the meaning of the nam";
setTextWithSpan(text,head+body,head, body,new android.text.style.StyleSpan(android.graphics.Typeface.BOLD));
自定义方法
public void setTextWithSpan(TextView textView, String text, String spanTextBold,String secondPartOfText,StyleSpan style) {
SpannableStringBuilder sb = new SpannableStringBuilder(text);
int start = text.indexOf(spanTextBold);
int end = start + spanTextBold.length();
sb.setSpan(style, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
//sb.setSpan(new ForegroundColorSpan(Color.BLUE), start, end ,0); // if you need a color
int startTwo = text.indexOf(secondPartOfText);
int endTwo = startTwo + secondPartOfText.length();
// sb.setSpan(new StyleSpan(Typeface.ITALIC),startTwo,endTwo , 0);
sb.setSpan(new RelativeSizeSpan(0.8f), startTwo, endTwo, 0);
textView.setText(sb);
}