在水平滚动视图滚动文本 [英] Scroll text in a horizontal scroll view
问题描述
我见过类似的问题,我的几个职位。然而,在这些帖子中提到的解决方案,也没有帮我解决这个问题。下面是这种情况。我有一个水平滚动视图一个TextView。这个想法尽快是作为文本(超过视图大小)被附加到TextView的,它必须被自动滚动结束。这里是布局片段。
I have seen a few posts similar to my issue. However, the solutions mentioned in those posts did not help me fix the problem. Here is the scenario. I have a TextView in a horizontal scroll view. The idea is as soon as a text (larger than the view) is appended to the TextView, it must be automatically scrolled to end. Here is the layout snippet.
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@color/subTitleColor"
android:fillViewport="true"
android:scrollbars="none" >
<TextView
android:id="@+id/drillPath"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="this is a such a long text that scrolling is needed, scroll more"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/textColorWhite" />
</HorizontalScrollView>
当一个事件,我这样做。
Upon an event, I do the following.
textView.append("do auto scroll");
有效地,它应该滚动文本到最后。但它不是!这是什么,我缺少什么呢?
Effectively, it should scroll the text to the end. But it isn't! What is it I am lacking?
推荐答案
首先,你的滚动视图将永远不会滚动,因为它的内容视图(TextView的)是 FILL_PARENT
模式。它应该换了内容,以留出空间的文本,并比其母公司大。 (你的TextView宽度更改为:的android:layout_width =WRAP_CONTENT
)
First of all, your scrollview will never scroll since its content view (the TextView) is in fill_parent
mode. it should wrap its content in order to leave space for the text and be bigger than its parent. (change your textView width to : android:layout_width="wrap_content"
)
那么,这里没有什么要求的滚动,我不认为它应该自动发生。
Then, there is nothing here to request the scroll, I don't think it should happen automatically.
添加像这样到滚动请求您的滚动视图的末尾:
Add something like this to request the scroll to the end of your scroll view :
textView.append("do auto scroll");
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_RIGHT);
}
});
让我知道,当你已经试过了。
Let me know when you've tried it.
这篇关于在水平滚动视图滚动文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!