git下载和说明地址:https://github.com/bingoogolapple/BGABanner-Android
XML代码:
<!--accordion平滑-->
<!--cube旋转-->
<!--defaultEffect正常-->
<cn.bingoogolapple.bgabanner.BGABanner
android:id="@+id/banner_guide_content"
style="@style/BannerDefaultStyle"
app:banner_indicatorGravity="bottom|left"
app:banner_transitionEffect="defaultEffect" />
说明:父控件声明:
xmlns:app="http://schemas.android.com/apk/res-auto"
<!--轮播图样式-->
<style name="BannerDefaultStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">200dp</item>
<!-- 自定义属性在styles.xml中不需要命名空间,直接用属性名就可以了 -->
<!-- 开启自动轮播 -->
<item name="banner_pointAutoPlayAble">true</item>
<!-- 自动轮播的时间间隔 -->
<item name="banner_pointAutoPlayInterval">3000</item>
<!-- 指示点容器背景 -->
<item name="banner_pointContainerBackground">#44aaaaaa</item>
<!-- 指示点背景 -->
<item name="banner_pointDrawable">@drawable/bga_banner_selector_point_hollow</item>
<!-- 指示点容器左右内间距 -->
<item name="banner_pointContainerLeftRightPadding">10dp</item>
<!-- 指示点上下外间距 -->
<item name="banner_pointTopBottomMargin">6dp</item>
<!-- 指示点左右外间距 -->
<item name="banner_pointLeftRightMargin">3dp</item>
<!-- 指示器的位置 -->
<item name="banner_indicatorGravity">bottom|center_horizontal</item>
<!-- 页码切换过程的时间长度 -->
<item name="banner_pageChangeDuration">800</item>
<!-- 提示文案的文字大小 -->
<item name="banner_tipTextSize">10sp</item>
<!-- 提示文案的文字颜色 -->
<item name="banner_tipTextColor">@android:color/white</item>
<!-- 加载网络数据时覆盖在BGABanner最上层的占位图 -->
<item name="banner_placeholderDrawable">@drawable/holder</item>
</style>
<declare-styleable name="BGABanner">
<!-- 指示点容器背景 -->
<attr name="banner_pointContainerBackground" format="reference|color" />
<!-- 指示点背景 -->
<attr name="banner_pointDrawable" format="reference" />
<!-- 指示点容器左右内间距 -->
<attr name="banner_pointContainerLeftRightPadding" format="dimension" />
<!-- 指示点上下外间距 -->
<attr name="banner_pointTopBottomMargin" format="dimension" />
<!-- 指示点左右外间距 -->
<attr name="banner_pointLeftRightMargin" format="dimension" />
<!-- 指示器的位置 -->
<attr name="banner_indicatorGravity">
<flag name="top" value="0x30" />
<flag name="bottom" value="0x50" />
<flag name="left" value="0x03" />
<flag name="right" value="0x05" />
<flag name="center_horizontal" value="0x01" />
</attr>
<!-- 是否开启自动轮播 -->
<attr name="banner_pointAutoPlayAble" format="boolean" />
<!-- 自动轮播的时间间隔 -->
<attr name="banner_pointAutoPlayInterval" format="integer" />
<!-- 页码切换过程的时间长度 -->
<attr name="banner_pageChangeDuration" format="integer" />
<!-- 页面切换的动画效果 -->
<attr name="banner_transitionEffect" format="enum">
<enum name="defaultEffect" value="0" />
<enum name="alpha" value="1" />
<enum name="rotate" value="2" />
<enum name="cube" value="3" />
<enum name="flip" value="4" />
<enum name="accordion" value="5" />
<enum name="zoomFade" value="6" />
<enum name="fade" value="7" />
<enum name="zoomCenter" value="8" />
<enum name="zoomStack" value="9" />
<enum name="stack" value="10" />
<enum name="depth" value="11" />
<enum name="zoom" value="12" />
</attr>
<!-- 提示文案的文字颜色 -->
<attr name="banner_tipTextColor" format="reference|color" />
<!-- 提示文案的文字大小 -->
<attr name="banner_tipTextSize" format="dimension" />
<!-- 加载网络数据时覆盖在BGABanner最上层的占位图 -->
<attr name="banner_placeholderDrawable" format="reference" />
<!-- 是否是数字指示器 -->
<attr name="banner_isNumberIndicator" format="boolean" />
<!-- 数字指示器文字颜色 -->
<attr name="banner_numberIndicatorTextColor" format="reference|color" />
<!-- 数字指示器文字大小 -->
<attr name="banner_numberIndicatorTextSize" format="dimension" />
<!-- 数字指示器背景 -->
<attr name="banner_numberIndicatorBackground" format="reference" />
<!-- 当只有一页数据时是否显示指示器,默认值为false -->
<attr name="banner_isNeedShowIndicatorOnOnlyOnePage" format="boolean" />
</declare-styleable>
Java调用代码:
private void no() {
List<String> url = new ArrayList<>();
BannerModel bannerModel = new BannerModel();
bannerModel.imgs = url;
mContentBanner.setAdapter(this);
mContentBanner.setData(bannerModel.imgs, bannerModel.tips);
}
//轮播图监听
public void fillBannerItem(BGABanner banner, View view, Object model, int position) {
Glide.with(getActivity())
.load(model)
.placeholder(R.drawable.holder)
.error(R.drawable.holder)
.into((ImageView) view);
}
配置代码:
compile 'cn.bingoogolapple:bga-banner:2.1.7@aar' compile 'com.android.support:support-v4:23.1.0' compile 'com.github.bumptech.glide:glide:3.5.2'//图片加载库