【发布时间】:2018-06-22 13:21:26
【问题描述】:
我正在制作简单的计算器,其设计类似于 Google 的计算器。我在 HorizontalScrollView 中有带有计算的文本,我希望它在键入时滚动到计算的末尾。我已经用这段代码(Kotlin)做到了:
textView.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
scrollVIew.fullScroll(HorizontalScrollView.FOCUS_RIGHT)
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
})
这里是带有滚动视图的 .xml 片段:
<HorizontalScrollView
android:id="@+id/scrollVIew"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="0"
android:textAlignment="textEnd"
android:textSize="75sp" />
</HorizontalScrollView>
而且这种方法很有效,当文本更新时,文本会滚动到最后一个聊天,但不是最后一个。有谁知道为什么?
【问题讨论】:
标签: android kotlin horizontalscrollview kotlin-android-extensions