布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:scrollbars="vertical"
android:singleLine="false" />
<include
android:id="@+id/content_layout"
layout="@layout/content" />
</ScrollView>
</RelativeLayout>
Activity中代码:
TextView tv_content=(TextView)findViewById(R.id.tv_content);
tv_content.setMovementMethod(ScrollingMovementMethod.getInstance());
tv_content.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 通知ScrollView控件不要干扰
v.getParent().requestDisallowInterceptTouchEvent(true);
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
// 通知ScrollView控件不要干扰
v.getParent().requestDisallowInterceptTouchEvent(true);
}
if (event.getAction() == MotionEvent.ACTION_UP) {
v.getParent().requestDisallowInterceptTouchEvent(false);
}
return false;
}
});