Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

动态设置指示器可见性没有生效 #330

Open
felicity520 opened this issue Jan 22, 2024 · 0 comments
Open

动态设置指示器可见性没有生效 #330

felicity520 opened this issue Jan 22, 2024 · 0 comments

Comments

@felicity520
Copy link

需求:指示器要先隐藏,然后根据左滑右滑让指示器显示
代码:
1、
binding.viewpagerImage.setAdapter(imageListAdapter).setAutoPlay(false).setCanLoop(true) .setIndicatorSlideMode(IndicatorSlideMode.NORMAL).setIndicatorVisibility(View.VISIBLE) .setIndicatorGravity(IndicatorGravity.END).setInterval(4000).setScrollDuration(300) .setIndicatorView(FigureIndicatorView(parent.context).apply { setRadius(DimenUtils.dpi2pxi(18)) setTextSize(DimenUtils.dpi2pxi(12)) setTextColor(Color.WHITE) setBackgroundColor(Color.parseColor("#80000000")) }).create()
2、
binding.viewpagerImage.setIndicatorVisibility(View.GONE)
测试:
发现指示器仍然可见,并没有隐藏
解决:
和作者沟通,可先暂时用反射来控制隐藏显示,以下是可用的代码
kotlin.runCatching { Timber.d("showImageIndicator:${show}") val bannerClazz: Class<*> = Class.forName("com.zhpan.bannerview.BannerViewPager") val indicatorLayoutField = bannerClazz.getDeclaredField("mIndicatorLayout") indicatorLayoutField.isAccessible = true val mIndicatorLayout = indicatorLayoutField.get(binding.viewpagerImage) as RelativeLayout val setVisibilityValue = if (show) View.VISIBLE else View.GONE if (mIndicatorLayout.visibility == setVisibilityValue){ return } val viewClazz: Class<*> = mIndicatorLayout.javaClass val setVisibilityMethod: Method = viewClazz.getMethod("setVisibility", Int::class.javaPrimitiveType) setVisibilityMethod.invoke(mIndicatorLayout, setVisibilityValue) }.onFailure { Timber.d("set Indicator setVisibility failed") }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant