Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show string depending upon width of the layout

I have created two layout vertically of equal width. And I have string data to be displayed on text view dynamically. When string is greater than the width of the layout then string is wrapped to the width of the layout and for remaining string I want to create a new TV dynamically. This process ends till remaining string finishes. For next string same process continues. When the process reaches bottom of linearlayout1, remaining string should starts from linearlayout2. And the process continues till it reaches bottom of linearlayout2.

I tried like this

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);
}

Illustration

enter image description here

like image 994
ShreeshaDas Avatar asked Jun 11 '13 13:06

ShreeshaDas


1 Answers

Possible Solution 1

What you need is a FlowLayout, found here. Basically the text needs to wrap around, instead of overflow to the right.

Possible Solution 2

Try to use a webview instead, and populate the text in 2 webviews. That will be faster with lesser code and not as buggy.

I used FlowLayout only when I needed to click on each word separately. Basically a test for grammar where people select the Parts Of Speech of the sentence. For that I needed listener on each word.

like image 110
Siddharth Avatar answered Oct 20 '22 01:10

Siddharth