Spotlight 无法正确点亮 NestedScrollView 内的组件

问题描述

我使用此 Spotlight 库在我的应用中创建演练:https://github.com/TakuSemba/Spotlight

一切正常,直到我尝试在 ViewPager 和 nestedScrollView 中使用聚光灯。

在这种情况下,当我点亮聚光灯内的第一个组件然后滚动到下一个组件时,我认为聚光灯会点亮下一个 Target(或我们的组件)的先前位置。请指导我如何解决这个问题?谢谢

这是我的聚光灯代码

fun startFundSpotlight(
    layoutInflater: LayoutInflater,activity: Activity,viewmodel: FundOverviewviewmodel
) {

    val targets = ArrayList<Target>()
    var spot: Spotlight? = null

    val fundDetailsRoot = FrameLayout(activity.applicationContext)
    val fundDetails =
        layoutInflater.inflate(R.layout.layout_fund_otp_user_walkthrough,fundDetailsRoot)


    val fundTarget = activity.findViewById<Button>(R.id.btn_fund_start)?.let {
        Target.Builder()
            .setAnchor(it)
            .setShape(RoundedRectangle(it.height.toFloat(),it.width.toFloat(),65f,200))
            .setoverlay(fundDetails)
            .setonTargetListener(object : OnTargetListener {
                override fun onStarted() {

                    val viewPager = activity.findViewById<ViewPager>(R.id.pagerFundWalkthrough)
                    val indicator = activity.findViewById<PagerIndicator>(R.id.pagerFundindicator)

                    viewPager.adapter =
                        OtpUserFundOverviewWalkthroughPagerAdapter(
                            activity.applicationContext
                        )

                    var current = 0

                    viewPager.addOnPagechangelistener(object : ViewPager.OnPagechangelistener {
                        override fun onPageScrolled(
                            position: Int,positionOffset: Float,positionOffsetPixels: Int
                        ) {
                        }

                        override fun onPageSelected(position: Int) {

                            indicator.current = position

                            if (position in (current + 1)..1) {
                                viewmodel.isFundSpotlightPresented.postValue(true)

                                fundDetails.refreshDrawableState()
                                fundDetails.postInvalidate()
                                spot?.next()


                            } else if (current > position && position <= 1) {
                                spot?.prevIoUs()
                                viewmodel.isFundSpotlightViewPagerMovePrevIoUs.postValue(true)
                            }

                            current = position
                        }

                        override fun onPageScrollStateChanged(state: Int) {}
                    })
                }

                override fun onEnded() {
                }
            })
            .build()
    }

    if (fundTarget != null) {
        targets.add(fundTarget)
    }


    val fundChartTarget = activity.findViewById<FrameLayout>(R.id.fundChart)?.let {
        Target.Builder()
            .setAnchor(it)
            .setShape(RoundedRectangle(it.height.toFloat(),5f,200))
            .setoverlay(fundDetails)
            .build()
    }

    if (fundChartTarget != null) {
        targets.add(fundChartTarget)
    }

    spot = Spotlight.Builder(activity)
        .setTargets(targets)
        .setBackgroundColorRes(R.color.spotlightBackground)
        .setDuration(200L)
        .setAnimation(DecelerateInterpolator(2f))
        .build()

    spot.start()

    val closeWalkthrough = View.OnClickListener {
        spot.finish()
    }

    fundDetails.findViewById<View>(R.id.txt_fund_walkthrough_quick_help_stop)
        .setonClickListener(closeWalkthrough)
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)