Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know why you might want to have multiple lines without a scrollbar, but if that's what you need I think this might be a possible solution. </p> <p>Obviously you will need some logic done onto your layout, because I can't think of a view that will give you this service without tweaking it some. </p> <p>So, I'm thinking a RelativeLayout with 5 TextViews (the number of textViews depends on how many lines you want to show). </p> <p>So each textView is going to contain one of your lines, so that when the user adds a new line you'd have to do something along these lines:</p> <pre><code>if( linesInView == 5 ) shiftText(); addText(); </code></pre> <p>So that <code>shiftText()</code> would be in charge of going through a loop and setting the text of one textView to another (shifting them), in order to make space for the new text. </p> <p>Then <code>addText()</code> would just add the new text created by the user onto the freed spot generated thanks to <code>shiftText()</code>.</p> <p>All in all you could follow these guidelines. Keep in mind that I have just written this code out of the top of my head, I don't have means to check its correctness at the moment. Also, this is a first try, there's room for improvement:</p> <pre><code>private static int MAX_NUM_LINES = 5; private int linesShown = 0; private ArrayList&lt;TextView&gt; views = new ArrayList&lt;&gt;(); private EditText userInput; public void onCreate(...){ .... views.add((TextView)findViewById(R.id.firstline); views.add((TextView)findViewById(R.id.secondline); views.add((TextView)findViewById(R.id.thirdline); views.add((TextView)findViewById(R.id.fourthline); views.add((TextView)findViewById(R.id.fifthline); this.userInput = (EditText) findViewById(R.id.input); //I suggest these in order to avoid calling "findViewById()" everytime the user // adds a new sentences, which I gather will happen often } public void someEventCalledWhenUserAddsNewLine(View view){ if(this.linesShown&gt;=MAX_NUM_LINES) shiftText(); addNewLine(); } private void shiftText(){ //Shift your text by looping through your this.views for(pos=0; pos&lt;this.views.size()-1; ++pos){ String nextLine = this.views.get(pos+1).getText(); this.views.get(pos).setText(nextLine); } //You need to set the condition to this.views.size()-1 because //when you reach position 4 (your last TextView) you have to sop // since there is not text to shift to that one this.views.get(this.views.size()-1).setText(null); //Make sure you set the text of the last TextView to null so that // addLine() will be able to find the first available TextView } private void addNewLine(){ //Add text from this.userInput to the first available TextView in this.views int pos; for(pos=0; pos&lt;this.views.size(); ++pos){ if(this.views.get(pos).getText()==null){ //We have found the first available TextView break; } } this.views.get(pos).setText(this.userInput.getText()); //Pos holds the position of the first available TextView, now we have // added the new line this.linesShown++; } </code></pre> <p>Top of the bat improvement would be to just keep track of the index of the first available TextView so you don't have to mess with the loop in <code>addLine()</code> looking for it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload