Skip to content

Commit

Permalink
添加了设置indicator 位置的api: 有两种方式,可以在代码中设置,也可以在xml文件中设置相关属性
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguo-zhouwei committed Mar 26, 2018
1 parent 3bd42ef commit 3d0989e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public void onPageScrollStateChanged(int state) {
bannerList.add(BANNER[i]);
}
mMZBanner.setIndicatorVisible(true);
// 代码中更改indicator 的位置
//mMZBanner.setIndicatorPadding(10,0,0,150);
mMZBanner.setPages(bannerList, new MZHolderCreator<BannerViewHolder>() {
@Override
public BannerViewHolder createViewHolder() {
Expand Down
45 changes: 36 additions & 9 deletions mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ private void readAttrs(Context context,AttributeSet attrs){
mIsOpenMZEffect = typedArray.getBoolean(R.styleable.MZBannerView_open_mz_mode,true);
mIsMiddlePageCover = typedArray.getBoolean(R.styleable.MZBannerView_middle_page_cover,true);
mIsCanLoop = typedArray.getBoolean(R.styleable.MZBannerView_canLoop,true);
mIndicatorAlign = typedArray.getInt(R.styleable.MZBannerView_indicatorAlign,1);
mIndicatorAlign = typedArray.getInt(R.styleable.MZBannerView_indicatorAlign,IndicatorAlign.CENTER.ordinal());
mIndicatorPaddingLeft = typedArray.getDimensionPixelSize(R.styleable.MZBannerView_indicatorPaddingLeft,0);
mIndicatorPaddingRight = typedArray.getDimensionPixelSize(R.styleable.MZBannerView_indicatorPaddingRight,0);
mIndicatorPaddingTop = typedArray.getDimensionPixelSize(R.styleable.MZBannerView_indicatorPaddingTop,0);
mIndicatorPaddingBottom = typedArray.getDimensionPixelSize(R.styleable.MZBannerView_indicatorPaddingBottom,0);
typedArray.recycle();
}


Expand All @@ -125,14 +126,7 @@ private void init(){
// 初始化Scroller
initViewPagerScroll();

if(mIndicatorAlign == 0){
setIndicatorAlign(IndicatorAlign.LEFT);
}else if(mIndicatorAlign == 1){
setIndicatorAlign(IndicatorAlign.CENTER);
}else{
setIndicatorAlign(IndicatorAlign.RIGHT);
}

sureIndicatorPosition();

}

Expand All @@ -153,6 +147,19 @@ private void setOpenMZEffect(){
}
}

/**
* make sure the indicator
*/
private void sureIndicatorPosition(){
if(mIndicatorAlign == IndicatorAlign.LEFT.ordinal()){
setIndicatorAlign(IndicatorAlign.LEFT);
}else if(mIndicatorAlign == IndicatorAlign.CENTER.ordinal()){
setIndicatorAlign(IndicatorAlign.CENTER);
}else{
setIndicatorAlign(IndicatorAlign.RIGHT);
}
}

/**
* 设置ViewPager的滑动速度
* */
Expand Down Expand Up @@ -326,6 +333,21 @@ public void setIndicatorVisible(boolean visible){
}
}

/**
* set indicator padding
* @param paddingLeft
* @param paddingTop
* @param paddingRight
* @param paddingBottom
*/
public void setIndicatorPadding(int paddingLeft,int paddingTop,int paddingRight,int paddingBottom){
mIndicatorPaddingLeft = paddingLeft;
mIndicatorPaddingTop = paddingTop;
mIndicatorPaddingRight = paddingRight;
mIndicatorPaddingBottom = paddingBottom;
sureIndicatorPosition();
}

/**
* 返回ViewPager
* @return {@link ViewPager}
Expand Down Expand Up @@ -452,6 +474,11 @@ public void setIndicatorAlign(IndicatorAlign indicatorAlign) {

}


public LinearLayout getIndicatorContainer() {
return mIndicatorContainer;
}

/**
* 设置ViewPager切换的速度
* @param duration 切换动画时间
Expand Down

0 comments on commit 3d0989e

Please sign in to comment.