码迷,mamicode.com
首页 > 其他好文 > 详细

解决EditText和ScrollView滑动冲突问题

时间:2016-09-18 14:52:38      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

该类需要调用
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); }

 

解决EditText和ScrollView滑动冲突问题

标签:

原文地址:http://www.cnblogs.com/niupi/p/5881325.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!