Search code examples
javaandroidandroid-listviewandroid-edittextsmooth-scrolling

How to accelerate smooth scrolling in Android multiline Edittext?


Here is the xml (activity_matches.xml) that displays the output in the screen shot below in an EditText object named txaMatches:

<EditText
    android:id=                     "@+id/txaMatches"
    android:text=                   ""

    android:scrollbars=             "vertical"
    android:layout_below=           "@+id/pattern"
    android:textColor=              "@color/yellow_foreground"
    android:textSize=               "@dimen/matches_text"
    android:focusable="false"
    android:inputType="textMultiLine"

    android:layout_width=           "wrap_content"
    android:layout_height=          "wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd=  "true"
    tools:ignore=                   "LabelFor"
    android:typeface="monospace"
    android:focusableInTouchMode="false"
    android:paddingEnd="@dimen/matches_padding"
    android:paddingStart="@dimen/matches_padding"
    />

enter image description here

I would like the contents of this multiline EditText object to scroll smoothly with acceleration if the user swipes inside it.

Here's how I fill txaMatches (using doInBackground). This is the only place in Java code that I refer to it (of course I also define and initialize it in Java):

protected void onProgressUpdate(String... progress)
{
  for (int i = 0; i < progress.length; i++)
    if(progress[i].length() > 1) MatchesActivity.txaMatches.append("\n" + progress[i]);
    else                         MatchesActivity.showLetter("Reading " + progress[i].charAt(0));
}

Is this an easy change to be made in xml?

Should I be using a ListView? Should the EditText be inside a ListView?

Am I going to have to write some Java code?

Given the small amount of code I've provided, I don't expect many details. Just an overview of what to Google would be a good start.


Solution

  • Pretty easy (thanks to Fllo's THIRD link). (The first was no help; the second focuses on Java code and the ScrollView class and is more involved than the third, which focuses on xml and was perfect for my situation (and required only changing the type of txaMatches to TextView):

    start of new code

    <ScrollView
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd=  "true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    

    end of new code except for closing tag

    <TextView
        android:id=                     "@+id/txaMatches"
        android:scrollbars=             "vertical"
        android:layout_width=           "wrap_content"
        android:layout_height=          "wrap_content"
        />
    </ScrollView>