中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

個人適合做什么網(wǎng)站域名??烤W(wǎng)頁推廣大全

個人適合做什么網(wǎng)站,域名停靠網(wǎng)頁推廣大全,個人網(wǎng)站可以做資訊小說類,武漢公司團(tuán)建去哪里好背景 ViewPager2內(nèi)嵌套橫向滑動的RecyclerView,會有滑動沖突的情況,引入官方提供的NestedScrollableHost類可以解決沖突問題,但是有一些瑕疵,滑動橫向RecyclerView到頂部,按住它不放手繼續(xù)往左拖再往右拖,這…

背景

在這里插入圖片描述
ViewPager2內(nèi)嵌套橫向滑動的RecyclerView,會有滑動沖突的情況,引入官方提供的NestedScrollableHost類可以解決沖突問題,但是有一些瑕疵,滑動橫向RecyclerView到頂部,按住它不放手繼續(xù)往左拖再往右拖,這時候會發(fā)現(xiàn)外層ViewPager2滑動了,而不是橫向RecyclerView滑動,于是參考NestedScrollableHost進(jìn)行邏輯完善

完整代碼

  • 主要是增加判斷外層ViewPager2是否可滾動來設(shè)置是否允許父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不聯(lián)動問題

如果布局CoordinatorLayout + AppBarLayout + ViewPager2內(nèi)嵌套橫向滑動的RecyclerView,這時拖拽橫向滑動的RecyclerView向上移,AppBarLayout不會跟著向上移

原因分析

  • 拖拽橫向滑動的RecyclerView向上移時,CoordinatorLayout.onNestedPreScroll內(nèi)的lp.isNestedScrollAccepted(type)返回false,造成AppBarLayout沒有執(zhí)行scroll
    在這里插入圖片描述

  • lp.isNestedScrollAccepted(type)被賦值的地方,會根據(jù)AppBarLayout$Behavior.onStartNestedScroll返回的accepted進(jìn)行賦值
    在這里插入圖片描述

  • AppBarLayout$Behavior.onStartNestedScroll內(nèi),會判斷nestedScrollAxes的值不是2就返回false
    在這里插入圖片描述

  • RecyclerView也支持嵌套滑動。startNestedScroll是由NestedScrollingChildHelper實(shí)現(xiàn)的,它會將嵌套滑動上傳,也就是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內(nèi)調(diào)用startNestedScroll會向上層view傳遞,直到交給CoordinatorLayout處理,而CoordinatorLayout在調(diào)用onStartNestedScroll的時候,AppBarLayout$Behavior.onStartNestedScroll又返回false了,造成CoordinatorLayout回調(diào)onNestedPreScroll(由RecyclerView在ACTION_MOVE時調(diào)用dispatchNestedPreScroll觸發(fā))時無法調(diào)用AppBarLayout的滾動。

解決方法

在CoordinatorLayout調(diào)用onStartNestedScroll的時候不處理橫向的情況,就不會導(dǎo)致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.risenshineclean.com/news/57691.html

相關(guān)文章:

  • 英文 日文網(wǎng)站建設(shè)申請線上營銷的優(yōu)勢
  • 一級a做爰片在線看網(wǎng)站公司搜索seo
  • 襄陽營銷型網(wǎng)站愛站網(wǎng)絡(luò)挖掘詞
  • 深圳最新消息公布長沙seo服務(wù)
  • 做調(diào)查問卷賺錢網(wǎng)站有哪些培訓(xùn)seo哪家學(xué)校好
  • 網(wǎng)站建設(shè)投訴去哪里投訴軟件推廣的渠道是哪里找的
  • 什么是網(wǎng)站域名?會計(jì)培訓(xùn)班要多少錢一般要學(xué)多久
  • 電子商務(wù)網(wǎng)站建設(shè)與管理習(xí)題答案免費(fèi)服務(wù)器
  • 免費(fèi)網(wǎng)站推廣工具有哪些百度搜索排行榜前十名
  • 如何做網(wǎng)站的的關(guān)鍵詞網(wǎng)絡(luò)培訓(xùn)學(xué)校
  • 免費(fèi)做網(wǎng)站wxp114百度愛采購優(yōu)化軟件
  • 長春市疫情最新消息今天行動軌跡湖南網(wǎng)站seo營銷
  • 258做網(wǎng)站怎么樣網(wǎng)站排名優(yōu)化+o+m
  • 自己做優(yōu)惠劵網(wǎng)站賺錢嗎網(wǎng)站seo是干什么的
  • 響應(yīng)式網(wǎng)站新聞部分怎么做aso優(yōu)化軟件
  • 順徳網(wǎng)站建設(shè)公司有哪些搜索關(guān)鍵詞排名優(yōu)化軟件
  • 臨沂品牌網(wǎng)站推廣人民日報(bào)今日新聞
  • ui設(shè)計(jì)技術(shù)培訓(xùn)學(xué)校十堰seo優(yōu)化
  • 房產(chǎn)這么做網(wǎng)站才多點(diǎn)擊量2023新聞熱點(diǎn)摘抄
  • 佳木斯建設(shè)工程交易中心網(wǎng)站自助建站
  • 建筑培訓(xùn)網(wǎng)站網(wǎng)絡(luò)廣告策劃的內(nèi)容
  • 青縣做網(wǎng)站價格好看的網(wǎng)站ui
  • 手機(jī)網(wǎng)站開放關(guān)鍵詞排名點(diǎn)擊軟件工具
  • 怎么做網(wǎng)站報(bào)告網(wǎng)絡(luò)輿情分析研判報(bào)告
  • 推薦10個網(wǎng)站電子商務(wù)網(wǎng)站開發(fā)
  • 天眼查 企業(yè)查詢官網(wǎng)seo網(wǎng)站推廣優(yōu)化
  • 網(wǎng)站設(shè)計(jì)網(wǎng)站開發(fā)百度推廣投訴人工電話
  • 西安網(wǎng)站策劃公司一呼百應(yīng)推廣平臺
  • 手機(jī)端首頁尺寸多少seo排名計(jì)費(fèi)系統(tǒng)
  • 做燈箱片的設(shè)計(jì)網(wǎng)站站長工具箱