如何在Android多行Edittext中加速平滑滚动?

时间:2016-01-11 16:46:22

标签: java android android-listview android-edittext smooth-scrolling

以下xmlactivity_matches.xml)在EditText名为txaMatches的{​​{1}}对象中显示以下屏幕截图中的输出:

<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

如果用户在其中滑动,我希望此multiline EditText对象的内容能够通过加速平滑滚动。

以下是我填写txaMatches的方式(使用doInBackground)。这是我引用它的Java代码中唯一的位置(当然我也用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));
}

这是否可以在xml中进行轻松更改?

我应该使用ListView吗? EditText是否应在ListView内?

我是否必须编写一些Java代码?

鉴于我提供的代码量很少,我不希望有太多细节。只是概述一下Google将是一个良好的开端。

1 个答案:

答案 0 :(得分:1)

非常简单(感谢Fllo的THIRD link)。 (第一个没有帮助;第二个专注于Java代码和ScrollView类,比第三个更重要,它侧重于xml并且非常适合我的情况(并且仅需要更改类型txaMatchesTextView):

开始新代码

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

除了结束标记

之外的新代码结束
<TextView
    android:id=                     "@+id/txaMatches"
    android:scrollbars=             "vertical"
    android:layout_width=           "wrap_content"
    android:layout_height=          "wrap_content"
    />
</ScrollView>