From 9d47e96117b6a7c5974f97e04385c6a901f0ed3b Mon Sep 17 00:00:00 2001 From: jingbin <770413277@qq.com> Date: Mon, 1 Mar 2021 20:17:44 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=A2=9E=E5=8A=A0=E6=8C=87=E7=A4=BA?= =?UTF-8?q?=E5=99=A8=E5=8F=AF=E8=AE=BE=E7=BD=AE=E8=B7=9D=E7=A6=BB=E5=B7=A6?= =?UTF-8?q?=E5=8F=B3=E4=BE=A7=E7=9A=84=E8=B7=9D=E7=A6=BB=20indicator=5Fmar?= =?UTF-8?q?gin=5Fleft/indicator=5Fmargin=5Fright?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/jingbin/sbanner/SBannerView.java | 60 ++++++++++++------- sbanner/src/main/res/values/attr.xml | 2 + 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/sbanner/src/main/java/me/jingbin/sbanner/SBannerView.java b/sbanner/src/main/java/me/jingbin/sbanner/SBannerView.java index e9edcbc..e0942f7 100755 --- a/sbanner/src/main/java/me/jingbin/sbanner/SBannerView.java +++ b/sbanner/src/main/java/me/jingbin/sbanner/SBannerView.java @@ -41,43 +41,58 @@ */ public class SBannerView extends FrameLayout implements OnPageChangeListener { + // 单个指示器左右的间距 private int mIndicatorPadding = BannerConfig.PADDING_SIZE; + // 指示器距离底部的高度 private int mIndicatorMargin = BannerConfig.MARGIN_BOTTOM; + // 指示器距离左侧的宽度 + private int mIndicatorMarginLeft = 0; + // 指示器距离右侧的宽度 + private int mIndicatorMarginRight = 0; + // 单个指示器的宽度 private int mIndicatorWidth; + // 单个指示器的高度 private int mIndicatorHeight; - private int indicatorSize; + // 指示器显示样式:不显示/自带/自定义 private int bannerStyle = BannerConfig.CIRCLE_INDICATOR; + // 滚动间隔时间 private int delayTime = BannerConfig.TIME; + // ViewPager切换滑动速度 时间越大速度越慢 private int scrollTime = BannerConfig.DURATION; + // 是否自动循环滚动,默认true private boolean isAutoPlay = BannerConfig.IS_AUTO_PLAY; + // ViewPager是否能手动滑动,默认true private boolean isScroll = BannerConfig.IS_SCROLL; + // 是否循环播放,false则循环一轮后停止,默认true private boolean isLoop = BannerConfig.IS_LOOP; - private int mIndicatorSelectedResId = R.drawable.gray_radius; - private int mIndicatorUnselectedResId = R.drawable.white_radius; - private Drawable mIndicatorSelectedDrawable; - private Drawable mIndicatorUnselectedDrawable; + // 滑动到头后,是否返回滑动,默认true,返回滑动! + private boolean isBackLoop = BannerConfig.IS_BACK_LOOP; + // 指示器的默认宽高 + private final int indicatorSize; + private static final int NUM = 5000; + private int count = 0; private int gravity = -1; private List mDatas; - private HolderCreator creator; + private int widthPixels; + private int lastPosition; + private int currentItem; + private int mPageLeftMargin; + private int mPageRightMargin; private List indicatorImages; + private HolderCreator creator; + private final WeakHandler handler = new WeakHandler(); + private Context context; - private BannerViewPager viewPager; - private int widthPixels; - // 指示器 private LinearLayout indicator; - + private BannerViewPager viewPager; private BannerPagerAdapter adapter; - private OnPageChangeListener mOnPageChangeListener; private OnBannerClickListener listener; - private int mPageLeftMargin; - private int mPageRightMargin; - private WeakHandler handler = new WeakHandler(); - // 默认true 滑到到最后一个时,是否返回滑动 - private boolean isBackLoop = BannerConfig.IS_BACK_LOOP; - private static final int NUM = 5000; - private int lastPosition; - private int currentItem; + private Drawable mIndicatorSelectedDrawable; + private Drawable mIndicatorUnselectedDrawable; + private OnPageChangeListener mOnPageChangeListener; + private int mIndicatorSelectedResId = R.drawable.gray_radius; + private int mIndicatorUnselectedResId = R.drawable.white_radius; public SBannerView(Context context) { this(context, null); @@ -107,9 +122,10 @@ private void initView(Context context, AttributeSet attrs) { params.rightMargin = mPageRightMargin; viewPager.setLayoutParams(params); indicator = (LinearLayout) view.findViewById(R.id.circleIndicator); - RelativeLayout.LayoutParams indicatorParam = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, - LayoutParams.WRAP_CONTENT); + RelativeLayout.LayoutParams indicatorParam = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); indicatorParam.bottomMargin = mIndicatorMargin; + indicatorParam.leftMargin = mIndicatorMarginLeft - mIndicatorPadding; + indicatorParam.rightMargin = mIndicatorMarginRight - mIndicatorPadding; indicator.setLayoutParams(indicatorParam); initViewPagerScroll(); } @@ -123,6 +139,8 @@ private void handleTypedArray(Context context, AttributeSet attrs) { mIndicatorHeight = typedArray.getDimensionPixelSize(R.styleable.SBannerView_indicator_height, indicatorSize); mIndicatorPadding = typedArray.getDimensionPixelSize(R.styleable.SBannerView_indicator_padding, BannerConfig.PADDING_SIZE); mIndicatorMargin = typedArray.getDimensionPixelSize(R.styleable.SBannerView_indicator_margin, BannerConfig.MARGIN_BOTTOM); + mIndicatorMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SBannerView_indicator_margin_left, 0); + mIndicatorMarginRight = typedArray.getDimensionPixelSize(R.styleable.SBannerView_indicator_margin_right, 0); mIndicatorSelectedResId = typedArray.getResourceId(R.styleable.SBannerView_indicator_drawable_selected, R.drawable.gray_radius); mIndicatorUnselectedResId = typedArray.getResourceId(R.styleable.SBannerView_indicator_drawable_unselected, R.drawable.white_radius); delayTime = typedArray.getInt(R.styleable.SBannerView_delay_time, BannerConfig.TIME); diff --git a/sbanner/src/main/res/values/attr.xml b/sbanner/src/main/res/values/attr.xml index de370cb..333841f 100755 --- a/sbanner/src/main/res/values/attr.xml +++ b/sbanner/src/main/res/values/attr.xml @@ -9,6 +9,8 @@ + +