Android 解决ScrollView嵌套EditText滑动冲突

ScrollView嵌套多行的EditText时,EditText内容滑动不了。

et.setOnTouchListener((view, motionEvent) -> {
	if ((view.getId() == R.id.et && canVerticalScroll(et))) {
 		view.getParent().requestDisallowInterceptTouchEvent(true);
    	if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
			view.getParent().requestDisallowInterceptTouchEvent(false);
       	}
	}
    return false;
});

// 判断EditText是否可滑动
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);
}
上一篇:Android入门 简易前后端分离 以登录功能为例


下一篇:综述文章梳理_刘 et al_2021_面向工业控制系统的入侵检测技术综述