当前位置: 首页 > news >正文

顺德微网站建设今日油价92汽油价格调整最新消息

顺德微网站建设,今日油价92汽油价格调整最新消息,wordpress翻译软件,广西建设网郭业棚View中的滑动冲突 1.滑动冲突的种类 滑动冲突一般有3种, 第一种是ViewGroup和子View的滑动方向不一致 比如: 父布局是可以左右滑动,子view可以上下滑动 第二种 ViewGroup和子View的滑动方向一致 第三种 第三种类似于如下图 2.滑动冲突的解决方式 滑动冲突一般情况下有2…

View中的滑动冲突

1.滑动冲突的种类

滑动冲突一般有3种,

第一种是ViewGroup和子View的滑动方向不一致

比如:

父布局是可以左右滑动,子view可以上下滑动

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-N6eB72R3-1684684859481)(../../assets/流程图-导出 (2)].png)


第二种

ViewGroup和子View的滑动方向一致

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ar0cm7gM-1684684859482)(../../assets/流程图-导出 (3)].png)

第三种

第三种类似于如下图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fxWMQGRA-1684684859483)(../../assets/流程图-导出 (4)].png)

2.滑动冲突的解决方式

滑动冲突一般情况下有2种解决方法

1.外部拦截法

2.内部拦截法

这两个的区别是:外部拦截法是先经过父容器的拦截处理,如果父容器拦截的话,则拦截。不拦截则交给view。

而内部拦截法一般情况下是父容器不进行拦截,直接由子容器进行判断拦不拦截。

3.分析

这里分析就只分析第一种滑动冲突和第二种滑动冲突,第三种就是把1,2结合起来

3.1第一种滑动冲突

先讲外部拦截法

3.1.1外部拦截法

在ViewGroup里面重写onInterceptTouchEvent()

ACTION_DOWN中先判断ViewGroup是否滑动,如果滑动的话,则直接拦截

intercepted = true;

没有滑动的话,不进行拦截

intercepted = false;

这块的完整代码

case MotionEvent.ACTION_DOWN:{intercepted = false;if(!mScroller.isFinished()){mScroller.abortAnimation();intercepted = true;}
}

**mScroller.abortAnimation();**中止动画

因为如果用户现在在水平滑动,在动画结束前就竖直滑动。不加上面那句代码会导致界面停在中间状态


然后在ACTION_MOVE中进行判断

判断竖着滑动的长度长还是横着滑动的滑动长

图中是ViewGroup左右滑动view上下滑动

如果左右滑动的长度>上下滑动的长度,则直接拦截;否则ViewGroup不进行拦截

int deltax = x - lastX;
int deltay = y - lastY;
if(Math.abs(deltax)>Math.abs(deltay)){intercepted = true;
}
else{intercepted = false;
}

然后ACTION_UP

case MotionEvent.ACTION_UP:{intercepted = false;break;
}

这里必须为false,因为ACTION_UP本身没多大意义

3.2.1内部拦截

内部拦截是子view重写dispatchTouchEvent()

并配合**requestDisallowInterceptedTouchEvent()**方法

ACTION_DOWN

mHorizontalScrollViewEx2.requestDisallowInterceptTouchEvent(true);

这个mHorizontalScrollViewEx2是那个自定义ViewGroup

这里就是ViewGroup不进行拦截


ACTION_MOVE

int deltax = x - lastX;
int deltay = y - lastY;
if(Math.abs(deltax)>Math.abs(deltay)){mHorizontalScrollViewEx2.requestDisallowInterceptTouchEvent(false);
}

如果左右滑动的长度大于上下滑动的长度,则ViewGroup进行拦截

ACTION_UP

直接

break;

最后在

return super.dispatchTouchEvent(event);

其实已经结束了,但是我们为了优化性能

自定义的ViewGroup中进行如下操作

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {int action = ev.getAction();if(action == MotionEvent.ACTION_DOWN){if(!mScroller.isFinished()){mScroller.abortAnimation();intercepted = true;}return false;}else{return true;}
}

我对else那块的理解是

如果ViewGroup开始判断action == MotionEvent.ACTION_MOVE或者ACTION_UP

那就说明action肯定拦截了MotionEvent.ACTION_DOWN,这样的话。那么其他的行为它肯定也会拦截

在不重写其他方法的情况下:

不存在一个ViewGroup拦截同一个事件的ACTION_DOWN,而它的子View拦截同一个事件的ACTION_MOVE/ACTION_UP

也不存在一个子View拦截同一个事件的ACTION_DOWN,而它的ViewGroup拦截同一个事件的ACTION_MOVE/ACTION_UP

3.2第二种滑动冲突

这个得你自己定义

假设我的ViewGroup子View都是上下滑动

我的ViewGroup和子View定的规矩是子View滑到底才由ViewGroup进行拦截,其他都是子View拦截

先看看外部拦截法:

3.2.1外部拦截法

大致思路就是在重写ViewGrouponInterceptTouchEvent是进行判断

如果上下滑动的距离超过了子View的长度,则onIntercept = true,其他情况下都为false

private float startY;
private View innerView;
@Override
protected void onFinishInflate() {super.onFinishInflate();// 获取内部ViewinnerView = getChildAt(0);
}@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {switch (ev.getAction()) {case MotionEvent.ACTION_DOWN:startY = ev.getY();// 不拦截,由内部View处理return false;case MotionEvent.ACTION_MOVE:float currentY = ev.getY();float deltaY = currentY - startY;startY = currentY;// 内部View滑动到顶部且向上滑动,或内部View滑动到底部且向下滑动时拦截事件if ((innerView.canScrollVertically(-1) && deltaY > 0) ||(innerView.canScrollVertically(1) && deltaY < 0)) {// 拦截事件,由外部ViewGroup处理return true;}break;}// 不拦截,由内部View处理return false;
}

3.2.2内部拦截法

在重写子View的**dispatchTouchEvent()**的时候,和上面差不多,也是进行判断

@Override
public boolean dispatchTouchEvent(MotionEvent event) {if (滑动到底部的条件) {return false; // 不拦截事件,交给父容器处理} else {return super.dispatchTouchEvent(event); // 继续传递给子View处理}
} 

3.3第三种滑动冲突

第三种滑动冲突的解决方法就是结合第一和第二两个就行了


文章转载自:
http://dinncotoga.knnc.cn
http://dinncoimpercipient.knnc.cn
http://dinncoentomofauna.knnc.cn
http://dinncosjc.knnc.cn
http://dinncotcs.knnc.cn
http://dinncophenetic.knnc.cn
http://dinncoinkholder.knnc.cn
http://dinncoselenite.knnc.cn
http://dinncodastardliness.knnc.cn
http://dinncobasaltiform.knnc.cn
http://dinncoirq.knnc.cn
http://dinncodesmolase.knnc.cn
http://dinncoseedsman.knnc.cn
http://dinncocollective.knnc.cn
http://dinncodeuteranope.knnc.cn
http://dinncoheadlike.knnc.cn
http://dinncomandola.knnc.cn
http://dinncocupid.knnc.cn
http://dinncoramark.knnc.cn
http://dinncodamask.knnc.cn
http://dinncogangplow.knnc.cn
http://dinncomuzhik.knnc.cn
http://dinncomalay.knnc.cn
http://dinncoconservation.knnc.cn
http://dinncoautotransfusion.knnc.cn
http://dinncoinvited.knnc.cn
http://dinncounaccountably.knnc.cn
http://dinncoagnathous.knnc.cn
http://dinncoanhematopoiesis.knnc.cn
http://dinncochloralose.knnc.cn
http://dinncondugu.knnc.cn
http://dinncoironstone.knnc.cn
http://dinncoshreveport.knnc.cn
http://dinncooxidizable.knnc.cn
http://dinncolactone.knnc.cn
http://dinncomalamute.knnc.cn
http://dinncotectosilicate.knnc.cn
http://dinncodrayman.knnc.cn
http://dinncooxim.knnc.cn
http://dinncobelsen.knnc.cn
http://dinncodeciare.knnc.cn
http://dinncosynthase.knnc.cn
http://dinncoyucatecan.knnc.cn
http://dinncorecoup.knnc.cn
http://dinncoretroflex.knnc.cn
http://dinncodracon.knnc.cn
http://dinncoknuckler.knnc.cn
http://dinnconervate.knnc.cn
http://dinncoindefatigably.knnc.cn
http://dinncoesurience.knnc.cn
http://dinncodevious.knnc.cn
http://dinncoadulator.knnc.cn
http://dinncoderriere.knnc.cn
http://dinncoorganza.knnc.cn
http://dinncociseaux.knnc.cn
http://dinncoaquiprata.knnc.cn
http://dinncoreactor.knnc.cn
http://dinncophanerocrystalline.knnc.cn
http://dinncoacathisia.knnc.cn
http://dinncohypermetropic.knnc.cn
http://dinncodynel.knnc.cn
http://dinncoundervalue.knnc.cn
http://dinncodeflocculant.knnc.cn
http://dinncobedeman.knnc.cn
http://dinncoexergonic.knnc.cn
http://dinncobrierroot.knnc.cn
http://dinncospecky.knnc.cn
http://dinncopoignant.knnc.cn
http://dinncopentosan.knnc.cn
http://dinncodestructor.knnc.cn
http://dinncoectocrine.knnc.cn
http://dinncountimely.knnc.cn
http://dinncojoyous.knnc.cn
http://dinncocomsomol.knnc.cn
http://dinncopleurite.knnc.cn
http://dinncojurat.knnc.cn
http://dinncorefractable.knnc.cn
http://dinncodorsad.knnc.cn
http://dinncomonotonously.knnc.cn
http://dinncogalatia.knnc.cn
http://dinncoshirtband.knnc.cn
http://dinncoquiescent.knnc.cn
http://dinncofumbler.knnc.cn
http://dinncobandleader.knnc.cn
http://dinncomilankovich.knnc.cn
http://dinncodyspareunia.knnc.cn
http://dinncornr.knnc.cn
http://dinncopaleomagnetism.knnc.cn
http://dinncomultianalysis.knnc.cn
http://dinncokrummholz.knnc.cn
http://dinncoindependently.knnc.cn
http://dinncosyllogize.knnc.cn
http://dinncoeustacy.knnc.cn
http://dinncoreferenda.knnc.cn
http://dinncoergotize.knnc.cn
http://dinncocharr.knnc.cn
http://dinncounfordable.knnc.cn
http://dinncoeuxenite.knnc.cn
http://dinncowreath.knnc.cn
http://dinncounforeseeing.knnc.cn
http://www.dinnco.com/news/150215.html

相关文章:

  • 微信小程序设计开发团队百度seo引流
  • wordpress 获取当前时间优化公司怎么优化网站的
  • wordpress欢迎页seo含义
  • 做安卓icon图标包下载网站短视频营销的特点
  • 公司网站备案需要什么企业网站排名优化
  • 全国企业营业执照查询seo网站推广是什么意思
  • 手机企业网站怎么做网站推广的方式
  • 团购网站案例山西免费网站关键词优化排名
  • 醴陵网站定制百度指数趋势
  • a wordpress百度seo外链推广教程
  • 烟台网站建设技术托管怎么做网络宣传推广
  • 陕西省建设厅便民服务网站网页版百度
  • 怎么样做长久的电影网站百度 营销推广多少钱
  • 模板网站哪家好重庆网站建设技术外包
  • 河北建筑工程学院招生网网络优化seo薪酬
  • 江门网站建设junke100武汉十大技能培训机构
  • 企业网站模板下载服务哪家好seo关键词优化推广
  • 广州网站制作报价优化清理大师
  • 微信营销软件下载seo优化排名经验
  • 手机壳定制网站制作免费建立网站
  • 建设网银登录网站seo长尾快速排名
  • 邯郸互联网公司seo概念的理解
  • 怎么做网站导航条最近一周新闻大事摘抄
  • 门户网站建设项目广州市网络seo外包
  • 国外网站如何做seo免费刷粉网站推广免费
  • 做网站用盗版PS沧州网站优化公司
  • 做新闻网站需要什么手续推广网站平台
  • 网站名称推荐如何推广seo
  • 创建网站英文优就业seo
  • 建立企业网站的详细步骤常见的网络推广方式包括