Skip to content

Commit

Permalink
添加Indicator 的上下左右边距设置
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguo-zhouwei committed Aug 27, 2017
1 parent 4614710 commit 3bd42ef
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onPageScrollStateChanged(int state) {
for(int i=0;i<BANNER.length;i++){
bannerList.add(BANNER[i]);
}
mMZBanner.setIndicatorVisible(false);
mMZBanner.setIndicatorVisible(true);
mMZBanner.setPages(bannerList, new MZHolderCreator<BannerViewHolder>() {
@Override
public BannerViewHolder createViewHolder() {
Expand All @@ -78,7 +78,6 @@ public BannerViewHolder createViewHolder() {
});

mNormalBanner = (MZBannerView) view.findViewById(R.id.banner_normal);
mNormalBanner.setIndicatorRes(R.color.colorAccent,R.color.colorPrimary);
mNormalBanner.setPages(list, new MZHolderCreator<BannerViewHolder>() {
@Override
public BannerViewHolder createViewHolder() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
app:middle_page_cover="true"
app:indicatorAlign="center"
app:indicatorPaddingLeft="10dp"
app:indicatorPaddingBottom="50dp"
/>

<TextView
Expand Down
12 changes: 10 additions & 2 deletions mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ public class MZBannerView<T> extends RelativeLayout {
private ArrayList<ImageView> mIndicators = new ArrayList<>();
//mIndicatorRes[0] 为为选中,mIndicatorRes[1]为选中
private int []mIndicatorRes= new int[]{R.drawable.indicator_normal,R.drawable.indicator_selected};
private int mIndicatorPaddingLeft = 0;
private int mIndicatorPaddingRight = 0;
private int mIndicatorPaddingLeft = 0;// indicator 距离左边的距离
private int mIndicatorPaddingRight = 0;//indicator 距离右边的距离
private int mIndicatorPaddingTop = 0;//indicator 距离上边的距离
private int mIndicatorPaddingBottom = 0;//indicator 距离下边的距离
private int mMZModePadding = 0;//在仿魅族模式下,由于前后显示了上下一个页面的部分,因此需要计算这部分padding
private int mIndicatorAlign = 1;
private ViewPager.OnPageChangeListener mOnPageChangeListener;
Expand Down Expand Up @@ -103,6 +105,8 @@ private void readAttrs(Context context,AttributeSet attrs){
mIndicatorAlign = typedArray.getInt(R.styleable.MZBannerView_indicatorAlign,1);
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);
}


Expand Down Expand Up @@ -440,6 +444,10 @@ public void setIndicatorAlign(IndicatorAlign indicatorAlign) {
}else{
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
}

// 2017.8.27 添加:增加设置Indicator 的上下边距。

layoutParams.setMargins(0,mIndicatorPaddingTop,0,mIndicatorPaddingBottom);
mIndicatorContainer.setLayoutParams(layoutParams);

}
Expand Down
2 changes: 2 additions & 0 deletions mzbanner/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<attr name="canLoop" format="boolean"/>
<attr name="indicatorPaddingLeft" format="dimension"/>
<attr name="indicatorPaddingRight" format="dimension"/>
<attr name="indicatorPaddingTop" format="dimension"/>
<attr name="indicatorPaddingBottom" format="dimension"/>
<attr name="indicatorAlign">
<enum name="left" value="0"/>
<enum name="center" value="1"/>
Expand Down

0 comments on commit 3bd42ef

Please sign in to comment.