解决EditText和ScrollView滑动冲突问题

该类需要调用
OnTouchListener接口
黄色部分是需要更改部分,改为自己的edittext
@Override
public boolean onTouch(View view, MotionEvent motionEvent) { //触摸的是EditText并且当前EditText可以滚动则将事件交给EditText处理;否则将事件交由其父类处理 if ((view.getId() == R.id.bags_stolen_characteristic_edittext && canVerticalScroll(mCharacteristiclEditText))) { view.getParent().requestDisallowInterceptTouchEvent(true); if (motionEvent.getAction() == MotionEvent.ACTION_UP) { view.getParent().requestDisallowInterceptTouchEvent(false); } } return false; } /** * EditText竖直方向是否可以滚动 * @param editText 需要判断的EditText * @return true:可以滚动 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); }
原文地址:https://www.cnblogs.com/niupi/p/5881325.html