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

英文外贸网站 php源码建设工程合同主体有哪些

英文外贸网站 php源码,建设工程合同主体有哪些,门业网站 模板,织梦笑话网站背景 ViewPager2内嵌套横向滑动的RecyclerView,会有滑动冲突的情况,引入官方提供的NestedScrollableHost类可以解决冲突问题,但是有一些瑕疵,滑动横向RecyclerView到顶部,按住它不放手继续往左拖再往右拖,这…

背景

在这里插入图片描述
ViewPager2内嵌套横向滑动的RecyclerView,会有滑动冲突的情况,引入官方提供的NestedScrollableHost类可以解决冲突问题,但是有一些瑕疵,滑动横向RecyclerView到顶部,按住它不放手继续往左拖再往右拖,这时候会发现外层ViewPager2滑动了,而不是横向RecyclerView滑动,于是参考NestedScrollableHost进行逻辑完善

完整代码

  • 主要是增加判断外层ViewPager2是否可滚动来设置是否允许父View拦截事件
open class NestRecyclerView @JvmOverloads constructor(context: Context,attrs: AttributeSet? = null
): RecyclerView(context, attrs) {private var initialX = 0fprivate var initialY = 0fprivate val parentViewPager: ViewPager2?get() {var v: View? = parent as? Viewwhile (v != null && v !is ViewPager2) {v = v.parent as? View}return v as? ViewPager2}private fun canViewScroll(target: View?, orientation: Int, delta: Float): Boolean {val direction = -delta.sign.toInt()return when (orientation) {0 -> target?.canScrollHorizontally(direction) ?: false1 -> target?.canScrollVertically(direction) ?: falseelse -> throw IllegalArgumentException()}}override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {val orientation = parentViewPager?.orientation ?: return super.onInterceptTouchEvent(event)if (!canViewScroll(this, orientation, -1f) && !canViewScroll(this, orientation, 1f)) {return super.onInterceptTouchEvent(event)}when (event?.action) {MotionEvent.ACTION_DOWN -> {initialX = event.xinitialY = event.yparent.requestDisallowInterceptTouchEvent(true)}MotionEvent.ACTION_MOVE -> {val dx = event.x - initialXval dy = event.y - initialYval isVpHorizontal = orientation == ViewPager2.ORIENTATION_HORIZONTALif (isVpHorizontal == dy.absoluteValue > dx.absoluteValue) {parent.requestDisallowInterceptTouchEvent(false)} else {if (canViewScroll(this, orientation, if (isVpHorizontal) dx else dy)) {parent.requestDisallowInterceptTouchEvent(true)} else {if (canViewScroll(parentViewPager, orientation, if (isVpHorizontal) dx else dy)) {parent.requestDisallowInterceptTouchEvent(false)} else {parent.requestDisallowInterceptTouchEvent(true)}}}}}return super.onInterceptTouchEvent(event)}
}

向上滑动AppBarLayout不联动问题

如果布局CoordinatorLayout + AppBarLayout + ViewPager2内嵌套横向滑动的RecyclerView,这时拖拽横向滑动的RecyclerView向上移,AppBarLayout不会跟着向上移

原因分析

  • 拖拽横向滑动的RecyclerView向上移时,CoordinatorLayout.onNestedPreScroll内的lp.isNestedScrollAccepted(type)返回false,造成AppBarLayout没有执行scroll
    在这里插入图片描述

  • lp.isNestedScrollAccepted(type)被赋值的地方,会根据AppBarLayout$Behavior.onStartNestedScroll返回的accepted进行赋值
    在这里插入图片描述

  • AppBarLayout$Behavior.onStartNestedScroll内,会判断nestedScrollAxes的值不是2就返回false
    在这里插入图片描述

  • RecyclerView也支持嵌套滑动。startNestedScroll是由NestedScrollingChildHelper实现的,它会将嵌套滑动上传,也就是NestedScrollingChild都会将嵌套滑动先交给NestedScrollingParent处理。

class RecyclerView...public boolean onInterceptTouchEvent(MotionEvent e) {if (mLayoutSuppressed) {// When layout is suppressed,  RV does not intercept the motion event.// A child view e.g. a button may still get the click.return false;}// Clear the active onInterceptTouchListener.  None should be set at this time, and if one// is, it's because some other code didn't follow the standard contract.mInterceptingOnItemTouchListener = null;if (findInterceptingOnItemTouchListener(e)) {cancelScroll();return true;}if (mLayout == null) {return false;}final boolean canScrollHorizontally = mLayout.canScrollHorizontally();final boolean canScrollVertically = mLayout.canScrollVertically();if (mVelocityTracker == null) {mVelocityTracker = VelocityTracker.obtain();}mVelocityTracker.addMovement(e);final int action = e.getActionMasked();final int actionIndex = e.getActionIndex();switch (action) {case MotionEvent.ACTION_DOWN:if (mIgnoreMotionEventTillDown) {mIgnoreMotionEventTillDown = false;}mScrollPointerId = e.getPointerId(0);mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f);mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f);if (mScrollState == SCROLL_STATE_SETTLING) {getParent().requestDisallowInterceptTouchEvent(true);setScrollState(SCROLL_STATE_DRAGGING);stopNestedScroll(TYPE_NON_TOUCH);}// Clear the nested offsetsmNestedOffsets[0] = mNestedOffsets[1] = 0;int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE;if (canScrollHorizontally) {nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL;}if (canScrollVertically) {nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL;}startNestedScroll(nestedScrollAxis, TYPE_TOUCH);break;...return mScrollState == SCROLL_STATE_DRAGGING;}

这里RecyclerView是横向的,所以nestedScrollAxis会被赋值为1,RecyclerView内调用startNestedScroll会向上层view传递,直到交给CoordinatorLayout处理,而CoordinatorLayout在调用onStartNestedScroll的时候,AppBarLayout$Behavior.onStartNestedScroll又返回false了,造成CoordinatorLayout回调onNestedPreScroll(由RecyclerView在ACTION_MOVE时调用dispatchNestedPreScroll触发)时无法调用AppBarLayout的滚动。

解决方法

在CoordinatorLayout调用onStartNestedScroll的时候不处理横向的情况,就不会导致lp.isNestedScrollAccepted(type)被赋值

class NestedCoordinatorLayout @JvmOverloads constructor(context: Context,attrs: AttributeSet? = null
): CoordinatorLayout(context, attrs) {override fun onStartNestedScroll(child: View, target: View, axes: Int, type: Int): Boolean {return if (axes and ViewCompat.SCROLL_AXIS_HORIZONTAL != 0) {false} else super.onStartNestedScroll(child, target, axes, type)}
}
http://www.yayakq.cn/news/36844/

相关文章:

  • 切图网站地方生活门户网站有哪些
  • 网站源码是啥六站合一的应用场景
  • 模板网站建设服务商网站建设采用的技术
  • 卫计网站建设工作总结保安网站建设
  • 网站建设 百度推广域名注册商推荐
  • 手机网站建设多少钿深圳网站建设哪个
  • 网站建设怎么开票专业的图纸设计网站
  • 加盟类网站怎么做枣庄手机网站开发
  • 自适应网站推广购物网站建设怎么样
  • 淘宝上网站建设是什么中国纪检监察报多久一期
  • 吉安市规划建设局网站石家庄房产网 二手房出售
  • 信用门户网站建设规范陵水网站建设报价
  • 网站建设服务哪家好 价格多少钱网站制作详细教程
  • 八年级信息网站怎么做wordpress mysql 密码
  • 怎么用别的网站做代理打开谷歌shopex网站搬家
  • 体育php网站源码广告平台源码
  • 西宁网站维护网络营销专业职业规划
  • 网站商城首页怎么做吸引人怎么做二维码微信扫后直到网站
  • 江西住房和城乡建设网站网站被很多公司抄袭
  • 梅州建站教程招商网站建设费用价格
  • 桓台新城建设有限公司网站宜兴市城乡建设局网站
  • 松江佘山网站建设单位建设网站的请示
  • 微网站在哪个平台上搭建好 知乎h5免费制作网站有哪些
  • 酒店为什么做网站seo证书考试网站
  • 中国纪检监察报网页seo搜索引擎优化
  • 广州做网站怎么样个人网站如何制作
  • 做国学类网站合法吗企业网站 免费
  • 网站页面设计说明怎么写新乡网站设计公司
  • 网站前台和后台对接实例物联网应用技术学什么就业方向
  • 网站建设价格山东济南兴田德润什么活动wordpress 文章发布时间