Skip to content

Commit

Permalink
setBannerData方法新增可传View集合
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnk25 committed Jan 5, 2022
1 parent 146a364 commit b79dff0
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions xbanner/src/main/java/com/stx/xhb/xbanner/XBanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public class XBanner extends RelativeLayout implements XBannerViewPager.AutoPlay
* 资源集合
*/
private List<?> mData;

/**
* 视图集合
*/
private List<View> mViews;
/**
* 是否只有一张图片
*/
Expand Down Expand Up @@ -238,10 +241,10 @@ public class XBanner extends RelativeLayout implements XBannerViewPager.AutoPlay
/*是否开启一屏显示多个模式*/
private boolean mIsClipChildrenMode;

/*一屏显示多个模式左右间距*/
/*一屏显示多个模式左间距*/
private int mClipChildrenLeftMargin;

/*一屏显示多个模式左右间距*/
/*一屏显示多个模式右间距*/
private int mClipChildrenRightMargin;

/*一屏显示多个模式上下间距*/
Expand Down Expand Up @@ -548,7 +551,7 @@ public void setData(@NonNull List<?> models, List<String> tips) {
}

/**
* 设置bannner数据
* 设置banner数据
*/
public void setBannerData(@LayoutRes int layoutResId, @NonNull List<? extends BaseBannerInfo> models) {
if (models == null) {
Expand All @@ -573,6 +576,37 @@ public void setBannerData(@LayoutRes int layoutResId, @NonNull List<? extends Ba
}
}

/**
* 设置banner数据
*/
public void setBannerData(@NonNull List<View> views, @NonNull List<? extends BaseBannerInfo> data) {
if (views == null) {
views = new ArrayList<>();
}
if (data == null) {
data = new ArrayList<>();
}
if (mViews.isEmpty()) {
mIsAutoPlay = false;
mIsClipChildrenMode = false;
}
if (!mIsClipChildrenModeLessThree && views.size() < 3) {
mIsClipChildrenMode = false;
}

this.mData = data;
this.mViews = views;
mIsOneImg = data.size() == 1;

initPoints();
initViewPager();
if (!data.isEmpty()) {
removeBannerPlaceHolderDrawable();
} else {
setBannerPlaceholderDrawable();
}
}

/**
* 设置数据和文案,布局资源默认为ImageView
*
Expand Down Expand Up @@ -676,7 +710,11 @@ private void initViewPager() {
* @return
*/
public int getRealCount() {
return mData == null ? 0 : mData.size();
if (mViews == null) {
return mData == null ? 0 : mData.size();
} else {
return mViews.size();
}
}

public XBannerViewPager getViewPager() {
Expand Down Expand Up @@ -770,9 +808,14 @@ public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
final View view = LayoutInflater.from(getContext()).inflate(layoutResId, container, false);
final int realPosition = getRealPosition(position);
View view;
if (mViews == null) {
view = LayoutInflater.from(getContext()).inflate(layoutResId, container, false);
} else {
view = mViews.get(realPosition);
}
if (getRealCount() > 0) {
final int realPosition = getRealPosition(position);
if (mOnItemClickListener != null && !mData.isEmpty()) {
view.setOnClickListener(new OnDoubleClickListener() {
@Override
Expand Down Expand Up @@ -957,10 +1000,10 @@ public void setAutoPlayAble(boolean mAutoPlayAble) {
/**
* 设置自动轮播时间间隔
*
* @param mAutoPalyTime
* @param mAutoPlayTime
*/
public void setAutoPalyTime(int mAutoPalyTime) {
this.mAutoPlayTime = mAutoPalyTime;
public void setAutoPlayTime(int mAutoPlayTime) {
this.mAutoPlayTime = mAutoPlayTime;
}

/**
Expand Down

0 comments on commit b79dff0

Please sign in to comment.