以下xml
(activity_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"
/>
如果用户在其中滑动,我希望此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将是一个良好的开端。
答案 0 :(得分:1)
非常简单(感谢Fllo的THIRD link)。 (第一个没有帮助;第二个专注于Java代码和ScrollView
类,比第三个更重要,它侧重于xml
并且非常适合我的情况(并且仅需要更改类型txaMatches
至TextView
):
开始新代码
<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>