BillBoardView自己定义控件广告板轮播

GitHub地址

compile ‘com.march.billboardview:billboardview:2.0.6-beta4’

BillBoardView

API

xml 里面使用

xml 里面使用
<com.march.billboardview.BillBoardView
android:id="@+id/billboard"
android:layout_width="match_parent"
android:layout_height="250dp"
board:isAutoRun="true"
board:isLoopIt="true"
board:intervalTime="2000" /> 属性:
isAutoRun:是不是自己主动播放,不须要滑动。默认true
isLoopIt:是不是无限循环播放。默认是true
intervalTime:播放间隔时间,每隔多长时间走一页

构建实体

//实体类实现获取url和title的接口
public class Demo implements BoardConfig{}

定义载入工具

//初始化图片载入的工具,你能够自己定义使用Picasso还是Glide等图片载入库载入
BillBoard.init(new BillBoard.BillLoadImg() {
@Override
public void loadImg(Context context, String title, String url, ImageView imageView) {
imageView.setImageResource(Integer.parseInt(url));
}
});

使用SimpleBoardAdapter

private BillBoardView billBoardView;
private SimpleBoardAdapter<Demo> mBoardAdapter;
mBoardAdapter = new SimpleBoardAdapter<>(getActivity(), demos);
billBoardView.setAdapter(mBoardAdapter);

配置BillBoardView,支持链式编程

billBoardView
.setAdapter(mBoardAdapter)
.setSwipeRefreshLayout(sw)
.click(new OnBoardClickListener() {
@Override
public void clickBillBoard(int pos, BoardConfig b) {
Log.e("chendong", "click pos " + pos + " title is " + b.getTitle());
}
}).show();

数据更新

mBoardAdapter.notifyDataSetChanged(demos);

开放停止和開始播放的方法

public void startPlay()
public void stopPlay()

当与SwipeRefreshLayout嵌套使用时,解决SwipeRefreshLayout冲突

public void setSwipeRefreshLayout(SwipeRefreshLayout sw)

设置轮播动画和时间,以下是可选的插值器,假设效果不足以满足要求,关于插值器的使用请自行百度

new AccelerateInterpolator()  開始慢后面加速,因为距离较近效果不明显,有点像是匀速
new AccelerateDecelerateInterpolator() 两头速度慢,中间加速,因为距离较近效果不明显,有点像是匀速
new DecelerateInterpolator() 開始快后面慢,因为距离较近效果不明显,有点像是匀速
new BounceInterpolator() 到达末尾跳跃弹起
new AnticipateInterpolator()先甩一下在移动
new AnticipateOvershootInterpolator() 先甩一下到达终点后过界在后退
new OvershootInterpolator() 过界后返回
new LinearInterpolator() 常量变速
new LinearOutSlowInInterpolator() 開始快后面慢
//设置动画的方法
public BillBoardView setAnimation(int duration, Interpolator interpolator)

BillBoardView其它API

//BillBoardView
//又一次定义ViewPager的将停
public void setOnBoardPageChangeListener(OnPageChangeListener onPageChangeListener)
//获取内部的ViewPager
public ViewPager getViewPager()

BoardAdapter

//一些变量,你能够在子类中訪问
protected Context mContext;
protected int mLyRes;
protected int preIndex = -1;//上一个被选中的
protected List<B> datas;
protected boolean isLoop;
protected View mRootView;
protected BillBoardView mBoardView;

基于SimpleBoardAdapter

//为了方便使用定义了SimpleBoardAdapter

//获取TitleView用于改变字体,颜色,背景,文字大小等
public TextView getTitleView()
//获取底部Bar,用于改变背景,高度等
public ViewGroup getBotLy()
//获取导航条
public LinearLayout getGuideLy()
//设置选中和未选中的资源
public void setSelectRes(int selectRes, int unSelectRes)
//设置标题的位置POS_LEFT = 0, POS_CENTER = 1, POS_RIGHT = 2
public void setTitleGravity(int gravity)
//设置导航栏的位置POS_LEFT = 0, POS_CENTER = 1, POS_RIGHT = 2
public void setGuideLyGravity(int gravity)

怎样自己定义Adapter

//Adapter做的工作是。覆盖在BillBoardView上面,随着BillBoardView的变化,改动UI
public class MyAdapter extends BoardAdapter<Demo> { public MyAdapter(Context mContext, List<Demo> datas) {
super(mContext, datas);
} //资源ID.高度建议Match_parent
@Override
protected int getLayoutId() {
return 0;
} //获取控件,findById()或者一些初始化的操作
@Override
protected void initAdapterViews() { } //当划到pos位置。更改界面显示
@Override
public void changeItemDisplay(int pos, Demo demo) { } //当adapter连接到billboardView时,触发
@Override
public void onBillBoardViewAttached(BillBoardView billBoardView) {
super.onBillBoardViewAttached(billBoardView);
}
}

当你的页面退出时,暂定轮播将是优化的一个非常好选择

    @Override
protected void onResume() {
super.onResume();
if(billBoardView!=null)
billBoardView.startPlay();
} @Override
protected void onDestroy() {
super.onDestroy();
billBoardView.stopPlay();
} @Override
protected void onPause() {
super.onPause();
billBoardView.stopPlay();
}

BillBoardView自己定义控件广告板轮播的更多相关文章

  1. Android自己定义控件之轮播图控件

    背景 近期要做一个轮播图的效果.网上看了几篇文章.基本上都能找到实现,效果还挺不错,可是在写的时候感觉每次都要单独去又一次在Activity里写一堆代码.于是自己封装了一下.这里仅仅是做了下封装成一个 ...

  2. Android自己定义控件之应用程序首页轮播图

    如今基本上大多数的Android应用程序的首页都有轮播图.就是像下图这种(此图为转载的一篇博文中的图.拿来直接用了): 像这种组件我相信大多数的应用程序都会使用到,本文就是自己定义一个这种组件,能够动 ...

  3. Android自定义控件1--自定义控件介绍

    Android控件基本介绍 Android本身提供了很多控件比如我们常用的有文本控件TextView和EditText:按钮控件Button和ImageButton状态开关按钮ToggleButton ...

  4. Qt 界面使用自己定义控件 &quot;提升为&quot;

    1.效果图 我做了一个很easy的样例,一个能够显示颜色的QLabel,边上有个button,点击,跳出颜色选取的Dialog,然后选择一个颜色.这个QLabel会变成什么颜色. 2.ColorLab ...

  5. Android自己定义控件(状态提示图表)

    [工匠若水 http://blog.csdn.net/yanbober 转载烦请注明出处.尊重分享成果] 1 背景 前面分析那么多系统源代码了.也该暂停下来歇息一下,趁昨晚闲着看见一个有意思的需求就操 ...

  6. 【Android】自己定义控件——仿天猫Indicator

    今天来说说类似天猫的Banner中的小圆点是怎么做的(图中绿圈部分) 在学习自己定义控件之前,我用的是很二的方法,直接在布局中放入多个ImageView,然后代码中依据Pager切换来改变图片.这样的 ...

  7. Android_declare-styleable_自己定义控件的属性

    1.简单实例 (1).在res/values文件下定义一个attrs.xml文件 <? xml version="1.0" encoding="utf-8" ...

  8. android学习七(创建自己定义控件)

    前面学习的是android的基本控件和布局的使用,可是主要的控件和布局有时候并不能实现复杂的布局.我们来看下各种控件和布局的关系. 可见全部的控件都是直接或者间接的继承自View的,全部的布局都是直接 ...

  9. Android自己定义控件系列五:自己定义绚丽水波纹效果

    尊重原创!转载请注明出处:http://blog.csdn.net/cyp331203/article/details/41114551 今天我们来利用Android自己定义控件实现一个比較有趣的效果 ...

随机推荐

  1. 802.11 MAC层

    1. 介绍 本文主要介绍了802.11 MAC层 2. 访问机制 CSMA/CA:  Carrier Sense Multiple Access with Collision Avoidance Wi ...

  2. 《Linux内核Makefile分析》之 auto.conf, auto.conf.cmd, autoconf.h【转】

    转自:http://blog.sina.com.cn/s/blog_87c063060101l25y.html 转载:http://blog.csdn.net/lcw_202/article/deta ...

  3. 使用Nginx+FFMPEG搭建HLS直播转码服务器

    目的:使Nginx支持Rtmp协议推流,并支持hls分发功能及FFMPEG转码多码率功能. 一.准备工作 模块:nginx-rtmp-module-master(支持rtmp协议) 下载地址: htt ...

  4. 详解BitMap算法

    所谓的BitMap就是用一个bit位来标记某个元素所对应的value,而key即是该元素,由于BitMap使用了bit位来存储数据,因此可以大大节省存储空间.   1. 基本思想 首先用一个简单的例子 ...

  5. 洛谷——P1690 贪婪的Copy

    P1690 贪婪的Copy 题目描述 Copy从卢牛那里听说在一片叫yz的神的领域埋藏着不少宝藏,于是Copy来到了这个被划分为个区域的神地.卢牛告诉了Copy这里共有个宝藏,分别放在第Pi个(1&l ...

  6. GCJ——Crazy Rows (2009 Round 2 A)

    题意: 给定一个N*N的矩阵,由0,1组成,只允许交换相邻的两行,把矩阵转化为下三角矩阵(对角线上方全是0),最少需要多少次交换?(保证可以转化为下三角矩阵) Large: N<=40 解析: ...

  7. php的session与免登陆问题

    Session 与 Session的GC 由于PHP的工作机制,它并没有一个daemon线程来定期的扫描Session 信息并判断其是否失效,当一个有效的请求发生时,PHP 会根据全局变量 sessi ...

  8. Eclipse4.4以上版本不能使用easyExplorer,采用OpenExplorer

    如果想在Ecipse里打开目录,一直用easyExplorer,可是现在版本升级了easyExplorer不好使,可以用OpenExplorer到https://github.com/samsonw/ ...

  9. ios6.0 siri语音识别

    Siri 让你能够利用语音来完成发送信息.安排会议.拨打电话等更多事务* .只需像平常一样讲话,就能让 Siri 帮你做事.你会发现 Siri 是如此易用而且能干,精彩用法越用你会发现越多. 懂你所说 ...

  10. 【spring cloud】@EnableTransactionManagement注解的意义

    @EnableTransactionManagement注解的意义