Skip to content

Commit

Permalink
Update Banner.java
Browse files Browse the repository at this point in the history
添加自定义指示器
  • Loading branch information
xiaomsh authored Aug 3, 2018
1 parent 93868d6 commit 403f296
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions rollbanner/src/main/java/com/ms/banner/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 403f296

Please sign in to comment.