Skip to content

Commit

Permalink
Update Banner
Browse files Browse the repository at this point in the history
  • Loading branch information
uncn committed Sep 5, 2018
1 parent ccc2f01 commit 08f77a0
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions Library/src/main/java/com/sunzn/banner/library/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,27 @@ private Drawable getDefaultDrawable(int color) {
}

private void createIndicators() {
if (mIsIndicatorShow && mLinearLayout != null) {
mLinearLayout.removeAllViews();
for (int i = 0; i < (mData == null ? 0 : mData.size()); i++) {
AppCompatImageView img = new AppCompatImageView(getContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.leftMargin = mIndicatorSpace / 2;
lp.rightMargin = mIndicatorSpace / 2;
if (mIndicatorSize >= dp2px(4)) {
lp.width = lp.height = mIndicatorSize;
} else {
img.setMinimumWidth(dp2px(2));
img.setMinimumHeight(dp2px(2));
if (mLinearLayout != null) {
if (mIsIndicatorShow) {
mLinearLayout.removeAllViews();
mLinearLayout.setVisibility(VISIBLE);
for (int i = 0; i < (mData == null ? 0 : mData.size()); i++) {
AppCompatImageView img = new AppCompatImageView(getContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.leftMargin = mIndicatorSpace / 2;
lp.rightMargin = mIndicatorSpace / 2;
if (mIndicatorSize >= dp2px(4)) {
lp.width = lp.height = mIndicatorSize;
} else {
img.setMinimumWidth(dp2px(2));
img.setMinimumHeight(dp2px(2));
}
img.setImageDrawable(i == 0 ? mIndicatorGainDrawable : mIndicatorMissDrawable);
mLinearLayout.addView(img, lp);
}
img.setImageDrawable(i == 0 ? mIndicatorGainDrawable : mIndicatorMissDrawable);
mLinearLayout.addView(img, lp);
} else {
mLinearLayout.removeAllViews();
mLinearLayout.setVisibility(GONE);
}
}
}
Expand Down Expand Up @@ -287,7 +293,9 @@ public void setBannerData(List<T> data) {
mData.clear();
mCurrentIndex = 0;
mData.addAll(data);
mIsIndicatorShow = false;
mBannerAdapter.notifyDataSetChanged();
createIndicators();
}
}
}
Expand Down

0 comments on commit 08f77a0

Please sign in to comment.