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.
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.
So, I'm thinking a RelativeLayout with 5 TextViews (the number of textViews depends on how many lines you want to show).
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:
if( linesInView == 5 )
shiftText();
addText();
So that shiftText()
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.
Then addText()
would just add the new text created by the user onto the freed spot generated thanks to shiftText()
.
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:
private static int MAX_NUM_LINES = 5;
private int linesShown = 0;
private ArrayList<TextView> views = new ArrayList<>();
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>=MAX_NUM_LINES)
shiftText();
addNewLine();
}
private void shiftText(){
//Shift your text by looping through your this.views
for(pos=0; pos<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<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++;
}
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 addLine()
looking for it.