Activity 中指示器 indicator 圆点不显示
24suixinsuoyu opened this issue · 3 comments
24suixinsuoyu commented
参考项目中 initHorizontalBanner()
和 initVerticalBanner()
代码设置 BannerViewPager
。结果 indicator 圆点不显示
代码如下:
private void initBanner() {
int normalWidth = getResources().getDimensionPixelOffset(R.dimen.dp_6);
int checkedWidth = getResources().getDimensionPixelOffset(R.dimen.dp_12);
int normalColor = ContextCompat.getColor(this, R.color.color_1A000000);
int checkedColor = ContextCompat.getColor(this, R.color.color_4D000000);
mBannerViewPager.setAutoPlay(true)
.setInterval(3000)
.setScrollDuration(500)
.setOffScreenPageLimit(2)
.setRoundCorner(R.dimen.dp_12)
.setIndicatorSliderGap(R.dimen.dp_4)
.setIndicatorView(mIndicatorView)
.setIndicatorVisibility(View.VISIBLE)
.stopLoopWhenDetachedFromWindow(true)
.disallowParentInterceptDownEvent(true)
.setIndicatorGravity(IndicatorGravity.END)
.registerLifecycleObserver((getLifecycle()))
.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
.setIndicatorSlideMode(IndicatorSlideMode.SCALE)
.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL)
.setIndicatorSliderWidth(normalWidth, checkedWidth)
.setIndicatorSliderColor(normalColor, checkedColor)
.setOnPageClickListener(this::onPageClicked)
.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
BannerBean bannerBean = mBannerViewPager.getData().get(position);
mTvBannerTitle.setText(bannerBean.getSpaceName());
}
}).setAdapter(mBannerAdapter).create();
}
24suixinsuoyu commented
去掉 setIndicatorSliderGap()
这行代码就可以 show 出来了
zhpanvip commented
setIndicatorSliderGap 你为什么设置的是一个 dimen 的引用值?这里应该是一个px的宽度
24suixinsuoyu commented
setIndicatorSliderGap 你为什么设置的是一个 dimen 的引用值?这里应该是一个px的宽度
额,我眼拙了。。setRoundCorner()
亦然。