在机器人制作的TextView滚动 [英] Making TextView Scrollable in Android

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

问题描述

我在看来是太长,不适合一个TextView显示文本 在一个屏幕上。我需要让我的TextView滚动。我能怎么做 那?这里是code

 最后的TextView电视=新的TextView(本);

   tv.setBackgroundResource(R.drawable.splash);
   tv.setTypeface(面);
   tv.setTextSize(18);
   tv.setTextColor(R.color.BROWN);

   tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);

   tv.setOnTouchListener(新OnTouchListener(){


           公共布尔onTouch(视图V,MotionEvent E)
           {


                   随机R =新的随机();
                   INT I = r.nextInt(101);

                   如果(e.getAction()== e.ACTION_DOWN)
                   {
                           tv.setText(提示[I]);
                           tv.setBackgroundResource(R.drawable.inner);


                   }

           返回true;
           }

   });

   的setContentView(电视);
 

解决方案

您不需要使用滚动型其实。

只需设置

 安卓MAXLINES =AN_INTEGER

机器人:滚动条=垂直
 

你的的TextView 在布局的xml文件

属性。

然后使用:

yourTextView.setMovementMethod(新ScrollingMovementMethod());

在你的code。

宾果游戏,它滚动!

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? Here is the code

   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);

解决方案

You don't need to use a ScrollView actually.

Just set the

android:maxLines = "AN_INTEGER"

android:scrollbars = "vertical"

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

Then use:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

in your code.

Bingo, it scrolls!

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

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