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