BGABanner记录

一、BGABanner简单用法

       1、XML:

<cn.bingoogolapple.bgabanner.BGABanner
        android:id="@+id/banner_guide_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:banner_pointAutoPlayAble="true"
        app:banner_pointAutoPlayInterval="3000"
        app:banner_pageChangeDuration="1000"
        app:banner_isNeedShowIndicatorOnOnlyOnePage="false"
        app:banner_pointDrawable="@drawable/banner_pointer_selector"
        app:banner_indicatorGravity="center_horizontal"
        app:banner_pointTopBottomMargin="@dimen/dp_5"
        app:banner_placeholderDrawable="@mipmap/place_holder_banner"
        app:banner_pointContainerBackground="@android:color/transparent"
        app:banner_transitionEffect="alpha"/>

        2、CODE:

//mBGABannerAdProTopSet是findViewById(R.id.banner_guide_content);
mBGABannerAdProTopSet.setEnterSkipViewId(0, 0);
//SimpleDraweeView是用到Freco的图片加载view,平时使用ImageView就可以,GetAdByPositionBean为加载资源实体类
mBGABannerAdProTopSet.setAdapter(new BGABanner.Adapter<SimpleDraweeView, GetAdByPositionBean>() {
    @Override
    public void fillBannerItem(BGABanner banner, final SimpleDraweeView itemView, GetAdByPositionBean model, int position) {
        itemView.setBackgroundColor(ColorUtils.getColor(getContext(), R.color.common_white));
        FrescoUtils.loadImage(itemView, model.adImageUrl);
    }
});
//设置点击事件
mBGABannerAdProTopSet.setDelegate(new BGABanner.Delegate<SimpleDraweeView, GetAdByPositionBean>() {
    @Override
    public void onBannerItemClick(BGABanner banner, SimpleDraweeView itemView, GetAdByPositionBean model, int position) {
        //事件处理
        clickAdImageAction(model);
    }
});
//banner_item_layout 包含一个SimpleDraweeView布局
//getAdByPositionBean List<图片路径等资源集合>
//null 每一页的提示文案集合
mBGABannerAdProTopSet.setData(R.layout.banner_item_layout, getAdByPositionBean, null);

二:具体方法 

banner_pointDrawable:指示器资源设置,用seletor改变选中与非选中资源

banner_pointContainerBackground:指示器布局背景

banner_indicatorGravity:指示器布局方式

banner_pointAutoPlayAble:是否自动播放

banner_pointAutoPlayInterval:自动播放间隔

banner_pageChangeDuration:页面切换的时间间隔,最多2000ms,相当于动画的间隔

banner_transitionEffect:页面切换动画选择(枚举)

banner_placeholderDrawable:加载换位图Id设置

banner_isNumberIndicator:是否启用数字指示器

banner_isNeedShowIndicatorOnOnlyOnePage:只一页时是否显示指示器

三:分析

自定义View的基本步骤

1、通过构造器获取xml参数

2、通过循环的方式与自定义的style匹配,设置初始值

3、setData方法调用时,设置指示器、Adapter等数据显示

知识点:

    a、实现onVisibilityChanged(以前不知道这个方法,记录下)方法,不可见时暂停自动播放,释放cpu

发布了5 篇原创文章 · 获赞 2 · 访问量 2639

猜你喜欢

转载自blog.csdn.net/u010413558/article/details/105628789