使TextView在Android上可滚动 [英] Making TextView scrollable on Android

查看:127
本文介绍了使TextView在Android上可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在文本视图中显示文本,该文本似乎太长而无法容纳 进入一个屏幕.我需要使TextView可滚动.我能怎么做 那?

I am displaying text in a textview that appears to be too long to fit into one screen. I need to make my TextView scrollable. How can I do that?

这是代码:

final TextView tv = new TextView(this);
tv.setBackgroundResource(R.drawable.splash);
tv.setTypeface(face);
tv.setTextSize(18);
tv.setTextColor(R.color.BROWN);
tv.setGravity(Gravity.CENTER_VERTICAL| Gravity.CENTER_HORIZONTAL);
tv.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent e) {
        Random r = new Random();
        int i = r.nextInt(101);
        if (e.getAction() == e.ACTION_DOWN) {
            tv.setText(tips[i]);
            tv.setBackgroundResource(R.drawable.inner);
        }
        return true;
    }
});
setContentView(tv);

推荐答案

您实际上不需要使用ScrollView.

只需设置

android:scrollbars = "vertical"

布局的xml文件中TextView

属性.

properties of your TextView in your layout's xml file.

然后使用:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

在您的代码中.

宾果游戏,它会滚动!

Bingo, it scrolls!

这篇关于使TextView在Android上可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆