让TextView内容滚动起来!另外解决会和ScrollView冲突的问题
布局文件中设置如下属性
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="5"
android:scrollbars="vertical" />
代码中添加该属性,即可实现TextView的滚动
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
以下是解决和ScrollView冲突的方案
textView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
scrollView.requestDisallowInterceptTouchEvent(true);
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
scrollView.requestDisallowInterceptTouchEvent(true);
}
if (event.getAction() == MotionEvent.ACTION_UP) {
scrollView.requestDisallowInterceptTouchEvent(false);
}
return false;
}
});
本文介绍如何让Android中的TextView内容滚动显示,并解决其与ScrollView之间的触摸事件冲突问题。通过设置TextView属性及使用ScrollingMovementMethod,配合特定的OnTouchListener实现。
3508

被折叠的 条评论
为什么被折叠?



