huburt-Hu / NewbieGuide

Android 快速实现新手引导层的库,通过简洁链式调用,一行代码实现引导层的显示
Apache License 2.0
3.56k stars 521 forks source link

Viewpager中的使用问题 #116

Open chenxi2035 opened 5 years ago

chenxi2035 commented 5 years ago

//added by isanwenyu@163.com fix bug #21 the wrong rect user will received in ViewPager if (tmp.getParent() != null && (tmp.getParent() instanceof ViewPager)) { tmp = (View) tmp.getParent(); }

ViewUtils中的这句代码,有些莫名奇妙,导致在指定自己的anchor时,位置计算时跳过了viewpager,跑到acitvity层的decorView了。

1136535305 commented 1 year ago

遇到了同样的问题,我的解决方法是手动计算RectF而不是通过anchorView

      /**
         * 调试时发现跳过测量RectF了ViewPage导致计算错误,所以直接计算出屏幕上的RectF
         */
        val anchorRect = RectF()
        val outLocation = IntArray(2)
        anchorView.getLocationOnScreen(outLocation)
        anchorRect.left = outLocation[0].toFloat()
        anchorRect.top = outLocation[1].toFloat()
        anchorRect.right = anchorRect.left + anchorView.measuredWidth
        anchorRect.bottom = anchorRect.top + anchorView.measuredHeight

        val guidePage = GuidePage.newInstance()
            .addHighLightWithOptions(anchorRect, HighLight.Shape.ROUND_RECTANGLE, dp2px(10), options)