該類需要調用
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);
}