From 403f29664ac9af272d09eb68de8ffd919a6a25fd Mon Sep 17 00:00:00 2001 From: wenchao <79556355@qq.com> Date: Fri, 3 Aug 2018 15:13:43 +0800 Subject: [PATCH] Update Banner.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加自定义指示器 --- .../src/main/java/com/ms/banner/Banner.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rollbanner/src/main/java/com/ms/banner/Banner.java b/rollbanner/src/main/java/com/ms/banner/Banner.java index aefea5b..8b7280f 100644 --- a/rollbanner/src/main/java/com/ms/banner/Banner.java +++ b/rollbanner/src/main/java/com/ms/banner/Banner.java @@ -271,6 +271,9 @@ private void setStyleUI() { case BannerConfig.CIRCLE_INDICATOR: indicator.setVisibility(visibility); break; + case BannerConfig.CUSTOM_INDICATOR: + indicator.setVisibility(visibility); + break; case BannerConfig.NUM_INDICATOR: numIndicator.setVisibility(visibility); break; @@ -322,7 +325,8 @@ private void setImageList(List datas) { if (bannerStyle == BannerConfig.CIRCLE_INDICATOR || bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE || - bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE) { + bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE || + bannerStyle == BannerConfig.CUSTOM_INDICATOR) { createIndicator(); } else if (bannerStyle == BannerConfig.NUM_INDICATOR_TITLE) { numIndicatorInside.setText("1/" + count); @@ -341,6 +345,10 @@ private void createIndicator() { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mIndicatorWidth, mIndicatorHeight); params.leftMargin = mIndicatorMargin; params.rightMargin = mIndicatorMargin; + LinearLayout.LayoutParams custom_params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + custom_params.leftMargin = mIndicatorMargin; + custom_params.rightMargin = mIndicatorMargin; if (i == 0) { imageView.setImageResource(mIndicatorSelectedResId); } else { @@ -352,6 +360,8 @@ private void createIndicator() { indicator.addView(imageView, params); else if (bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE) indicatorInside.addView(imageView, params); + else if (bannerStyle == BannerConfig.CUSTOM_INDICATOR) + indicator.addView(imageView, custom_params); } if (gravity != -1) indicator.setGravity(gravity); @@ -515,7 +525,8 @@ public void onPageSelected(int position) { } if (bannerStyle == BannerConfig.CIRCLE_INDICATOR || bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE || - bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE) { + bannerStyle == BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE || + bannerStyle == BannerConfig.CUSTOM_INDICATOR) { indicatorImages.get((lastPosition - 1 + count) % count).setImageResource(mIndicatorUnselectedResId); indicatorImages.get((position - 1 + count) % count).setImageResource(mIndicatorSelectedResId); lastPosition = position; @@ -529,6 +540,8 @@ public void onPageSelected(int position) { switch (bannerStyle) { case BannerConfig.CIRCLE_INDICATOR: break; + case BannerConfig.CUSTOM_INDICATOR: + break; case BannerConfig.NUM_INDICATOR: numIndicator.setText(position + "/" + count); break;