解決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); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM