android中TextView嵌套在ScrollView中并自由滚动

布局文件:



    
	
        
            
              
            
        
	


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


你可能感兴趣的:(android)