需要像一个独特的文本块一样依次格式化几个textview,有没有办法做到这一点?
像这样
__________________________
| |
| |
| aaaaaa bbbbbbbbbbbbbbb |
| bbbbbbbbbb cccccc dddd |
| ddddddddddddd. |
| |
我不能将 textview 放在 LinearLayout 中,因为我会获得这种效果:
__________________________
| |
| |
| aaaaaa bbbbbbbbbbbbbbb |
| bbbbbbbbbb |
| |
| |
任何的想法?
更新:通过可扩展解决
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);