解决EditText和ScrollView的滚动冲突

//设置监听 editText.setOnTouchListener(this); //重写Touch实践 @Override public boolean onTouch(View view, MotionEvent motionEvent) { //触摸的是EditText并且当前EditText可以滚动则将事件交给EditText处理;否则将事件交由其父类处理 if ((view.getId() == R.id.edittext && canVerticalScroll(editText))) { view.getParent().requestDisallowInterceptTouchEvent(true); if (motionEvent.getAction() == MotionEvent.ACTION_UP) { view.getParent().requestDisallowInterceptTouchEvent(false); } } return false; }/** * EditText竖直方向是否可以滚动 * @param editText需要判断的EditText * @returntrue:可以滚动false:不可以滚动 */ private boolean canVerticalScroll(EditText editText) {//滚动的距离int scrollY = editText.getScrollY(); //控件内容的总高度int scrollRange = editText.getLayout().getHeight(); //控件实际显示的高度int scrollExtent = editText.getHeight() - editText.getCompoundPaddingTop() -editText.getCompoundPaddingBottom(); //控件内容总高度与实际显示高度的差值int scrollDifference = scrollRange - scrollExtent; if(scrollDifference == 0) {return false; }return (scrollY > 0) || (scrollY < scrollDifference - 1); }

    推荐阅读