Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8816519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:38:25+00:00 2026-06-14T04:38:25+00:00

I have a TextView within a ScrollView, which currently scrolls to the bottom of

  • 0

I have a TextView within a ScrollView, which currently scrolls to the bottom of the TextView.

The TextView is filled dynamically constantly updating (the TextView is essentially acting as an actions console).

However, the problem I am having is that when the dynamic text is added to the ScrollView, the user can scroll past the text into black space, which is increasing everytime more content is added to the TextView.

I have tried various different apporaches however none of these gave the right outcome. I cannot use maxLines or define height of the layouts as I need this to be dynamic for the various screen sizes, which the number of lines visible constantly changing.

I had also orginally done this progromatically, however this was crashing at random time and therefore would like to keep it in my layout (better usabilty), example code below:

final int scrollAmount = update.getLayout().getLineTop(update.getLineCount()) - update.getHeight();
if(scrollAmount > 0)
{
    update.scrollTo(0, scrollAmount);
}

The code below is my current layout xml being used to automatically scroll my TextView to the bottom as content is added:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/spacer2"
    android:layout_below="@+id/spacer1"
    android:fillViewport="true" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/battle_details"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="12dp"
            android:layout_gravity="bottom" />
    </LinearLayout>
</ScrollView>

enter image description here

EDIT – This is the code I am using to add text to my TextView:

private void CreateConsoleString()
{
    TextView update = (TextView)findViewById(R.id.battle_details);
    String ConsoleString = "";
    // BattleConsole is an ArrayList<String>
    for(int i = 0; i < BattleConsole.size(); i++)
    {
        ConsoleString += BattleConsole.get(i) + "\n";
    }
    update.setText(ConsoleString);
}

EDIT 2 – I add content to the BattleConsole like this:

BattleConsole.add("Some console text was added");
CreateConsoleString();

To sum up my only issue is the ScrollView and/or TextView is adding blank space to the bottom rather than stop the user from scrolling at the last line of text. Any help or guidence as to where I am going wrong would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:38:26+00:00Added an answer on June 14, 2026 at 4:38 am

    It looks like that when you call

    BattleConsole.get(i) 
    

    it sometimes returns an empty String so you are just basically adding new lines to your TextView.

    You can do this for example:

    StringBuilder consoleString = new StringBuilder();
    // I'm using a StringBuilder here to avoid creating a lot of `String` objects
    for(String element : BattleConsole) {
        // I'm assuming element is not null
        if(!"".equals(element)) {
            consoleString.append(element);
            consoleString.append(System.getProperty("line.separator")); // I'm using a constant here.
        }
    }
    update.setText(consoleString.toString());
    

    If you could post the code of BattleConsole I could help you more.

    As a footnote: it is encouraged to use camelCase in java. Only class names start with capital letters in java according to the convention.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have a ListView with a TextView within each child. That TextView is
I have a TextView which i set the text using setText(). In properties, I
If we click any of the Textview within a Listview, background color should have
I have been working on the implementation of buttons to update a textview within
I have a TextView and I want to apply a Style which I use
I have a list view which has a couple of views within it, I
I have a class (TextEditorViewController) within there is a NSTextView (textView) Object. I've connected
I have a problem updating my AppWidget from within a Service. The problem seems
I have a Scrollview as a parent view, within that i have placed some
I have a number of TextView s that each share a single OnLongClickListener Within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.