需要像一个独特的文本块一样接着格式化几个textview,有没有办法实现这个目标?
像这样__________________________
| |
| |
| aaaaaa bbbbbbbbbbbbbbb |
| bbbbbbbbbb cccccc dddd |
| ddddddddddddd. |
| |
我无法将textview放在LinearLayout中,因为我将获得此效果:
__________________________
| |
| |
| aaaaaa bbbbbbbbbbbbbbb |
| bbbbbbbbbb |
| |
| |
任何想法?
更新:解决了SPANNABLES
String[] testString = { "this is a test ", "for testing click in different region", "of the textview"};
LinearLayout linear = new LinearLayout(this);
TextView textview = new TextView(this);
textview.setMovementMethod(LinkMovementMethod.getInstance());
SpannableStringBuilder builder = new SpannableStringBuilder();
int start = 0;
int end = 0;
for (String span : testString) {
start = end == 0 ? end : end + 1;
end = start + span.length();
final String spanned = span;
builder.append(span);
builder.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
Log.e("Clicked on:", spanned);
}
}, start, end, 0);
Log.e("TEST", span);
}
textview.append(builder);
linear.addView(textview);
setContentView(linear);