使 TextView 在 Android 上可滚动 [英] Making TextView scrollable on Android
本文介绍了使 TextView 在 Android 上可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 TextView 中显示的文本似乎太长而不适合进入一个屏幕.我需要使我的 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
.
You don't need to use a ScrollView
actually.
只需设置
android:scrollbars = "vertical"
布局的 xml 文件中 TextView
的属性.
properties of your TextView
in your layout's xml file.
然后使用:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
在您的代码中.
宾果游戏,它会滚动!
这篇关于使 TextView 在 Android 上可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文