0

我正在使用滚动视图中的文本视图创建可运行的打字机效果。

这就是我所做的......

    final ScrollView sv = new ScrollView(this);
    sv.setLayoutParams(new LinearLayout.LayoutParams((int)display.getWidth()/2, (int)((display.getHeight()/4))*3));
    sv.setPadding(0, px2DP(10), px2DP(10), px2DP(10));

    final CharSequence text = getResources().getText(R.string.longstring);

    final TextView content = new TextView(this);
    content.setBackgroundColor(getResources().getColor(R.color.Black));
    content.setTextColor(getResources().getColor(R.color.White));
    content.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
    content.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

    sv.addView(content);

    content.postDelayed(new Runnable(){
        @Override
        public void run() {
            content.append(text.subSequence(0, index++));
            sv.fullScroll(View.FOCUS_DOWN);     
        }

    },70);

我只得到一个黑匣子,没有文字。

我究竟做错了什么?请帮忙。

PS。我已经找到了解决方案!

4

1 回答 1

0

找到解决方案。我使用错误的处理程序可运行概念。根据 Jonas 所指出的,Runnable 只运行一次。因此需要一个循环。

正如此链接所建议的那样: 如何在 Android 中运行 Runnable 线程?

答案类似于递归。

总之谢谢各位!安卓太酷了。

于 2012-05-09T04:33:13.853 回答