//Edittext通知父控件自己处理自己的滑动事件 contentEt.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (v.getId() == R.id.content_et && canVerticalScroll(contentEt)) { v.getParent().requestDisallowInterceptTouchEvent(true); if (event.getAction() == MotionEvent.ACTION_UP) { v.getParent().requestDisallowInterceptTouchEvent(false); } } return false; } });
/** * EditText竖直方向是否可以滚动 * * @param //editText需要判断的EditText * @return true:可以滚动 false:不可以滚动 */ private boolean canVerticalScroll(EditText contentEt) { //滚动的距离 int scrollY = contentEt.getScrollY(); //控件内容的总高度 int scrollRange = contentEt.getLayout().getHeight(); //控件实际显示的高度 int scrollExtent = contentEt.getHeight() - contentEt.getCompoundPaddingTop() - contentEt.getCompoundPaddingBottom(); //控件内容总高度与实际显示高度的差值 int scrollDifference = scrollRange - scrollExtent; if (scrollDifference == 0) { return false; } return (scrollY > 0) || (scrollY < scrollDifference - 1); }