我在 TextView 中显示的文本似乎太长而无法容纳 进入一个屏幕。我需要让我的 TextView 可滚动。我能怎么做 那个?
代码如下:
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"
你的 TextView
在你的布局的 xml 文件中的属性。
然后使用:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
在您的代码中。
宾果游戏,它会滚动!
关于android - 使 TextView 在 Android 上可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1748977/