Title: Q - Display Text like Command Prompt in Android
Tags: android
Question: Is there a way to display text strings on the screen in a similar look to command prompt for windows, i.e. text fills the bottom-most line and stays on the screen as new lines are added below it? I feel like Canvas.drawTextOnPath can be used for this?

Here is the accepted answer: There's probably a bunch of ways to do this, depending on what you're using it for. Here's what I would do:
Add a LinearLayout with android:gravity="bottom", and add your TextView to that layout.
When you add text to it, use something like:
public ArrayList<String&gt; text = new ArrayList<String&gt;();
int lines = 20;
TextView textField = (TextView)findViewById(R.id.textview);
private String concatLines(){
String txt = "";
for(String s: text){
txt += s+"\n";
return txt.substring(0, txt.length()-1);
private void appendLine(String line){
text.add(line);
if(text.size() &gt; lines){
text.remove(0);
textField.setText(concatLines());
appendLine("&gt; A new line");
The android:gravity="bottom" should keep your text field aligned at the bottom of the layout. Make sure the TextView's height is wrap_content.
Comment for this answer: So int lines defines how many lines of text are still in the "buffer" so to speak?
Comment for this answer: Ah, so the text history cannot extend beyond the top of the screen right?
Comment for this answer: Can I also use a second array to hold all the text that goes out of the screen(by adding the line to the second array before I remove it) and then just have a page up/down button that cycles through that second array?
Comment for this answer: Right. This method obviously has some pitfalls, such as: if the buffer is more than the height of the TextView, it will be clipped on the bottom instead of at the top how you'd probably desire.
Comment for this answer: Right. To do that, you could look into using a ScrollView to wrap the TextView (and auto-scrolling to the bottom), or extend the TextView class and change the way it draws text.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:10/10/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android>', 'Title': 'Q - Display Text like Command Prompt in Android', 'ViewCount': 184, 'id': 19285277, 'user_AboutMe': '<p>My primary languages and skills include Javascript, HTML, CSS, Node.js/Express, and MongoDB. I also have experience in C#, C, C++, SQLite, MS SQL Server, and Xamarin.Android. I am self-taught and have learned all my programming skill on my own. If you would like to see more information about me or my work and projects in more detail, visit my website at www.ypinskiy.com.</p>\n', 'user_AccountId': 2969800.0, 'user_DisplayName': 'GPinskiy', 'user_Reputation': 187.0, 'user_Views': 53.0, 'user_id': 2522121.0}}