我创建了两个宽度相等的垂直布局。而且我有要在文本视图上动态显示的字符串数据。当字符串大于布局的宽度时,字符串被包装到布局的宽度,对于剩余的字符串,我想动态创建一个新的电视。此过程结束,直到剩余的字符串完成。对于下一个字符串,相同的过程继续。当进程到达linearlayout1的底部时,剩余的字符串应该从linearlayout2开始。这个过程一直持续到它到达linearlayout2的底部。
我试过这样
private void nextlinechar(int numChars,String devstr) {
nextchar=devstr;
Log.d("char 1",""+nextchar);
TextView sub=new TextView(getApplicationContext());
sub.setLines(1);
sub.setTextColor(Color.BLACK);
sub.setTextSize(textsize);
sub.setText(nextchar);
nextchar=devstr.substring(nextcharstart);
String textToBeSplit = nextchar; // Text you want to split between TextViews
String data=TextMeasure(nextchar,sub);
float myTextSize=sub.getTextSize();
float textView2Width=400;
// String next=TextMeasure(nextchar,sub);
Paint paint = new Paint();
paint.setTextSize(myTextSize); // Your text size
numChars1= paint.breakText(textToBeSplit, true,textView2Width, null);
nextchar1=nextchar.substring(numChars1);
// Log.d("char",""+i+" "+nextchar.length());
main.addView(sub);
nextlinechar(numChars1,nextchar);
}
插图