BillBoardView自己定义控件广告板轮播
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自己定义控件广告板轮播的更多相关文章
- Android自己定义控件之轮播图控件
背景 近期要做一个轮播图的效果.网上看了几篇文章.基本上都能找到实现,效果还挺不错,可是在写的时候感觉每次都要单独去又一次在Activity里写一堆代码.于是自己封装了一下.这里仅仅是做了下封装成一个 ...
- Android自己定义控件之应用程序首页轮播图
如今基本上大多数的Android应用程序的首页都有轮播图.就是像下图这种(此图为转载的一篇博文中的图.拿来直接用了): 像这种组件我相信大多数的应用程序都会使用到,本文就是自己定义一个这种组件,能够动 ...
- Android自定义控件1--自定义控件介绍
Android控件基本介绍 Android本身提供了很多控件比如我们常用的有文本控件TextView和EditText:按钮控件Button和ImageButton状态开关按钮ToggleButton ...
- Qt 界面使用自己定义控件 "提升为"
1.效果图 我做了一个很easy的样例,一个能够显示颜色的QLabel,边上有个button,点击,跳出颜色选取的Dialog,然后选择一个颜色.这个QLabel会变成什么颜色. 2.ColorLab ...
- Android自己定义控件(状态提示图表)
[工匠若水 http://blog.csdn.net/yanbober 转载烦请注明出处.尊重分享成果] 1 背景 前面分析那么多系统源代码了.也该暂停下来歇息一下,趁昨晚闲着看见一个有意思的需求就操 ...
- 【Android】自己定义控件——仿天猫Indicator
今天来说说类似天猫的Banner中的小圆点是怎么做的(图中绿圈部分) 在学习自己定义控件之前,我用的是很二的方法,直接在布局中放入多个ImageView,然后代码中依据Pager切换来改变图片.这样的 ...
- Android_declare-styleable_自己定义控件的属性
1.简单实例 (1).在res/values文件下定义一个attrs.xml文件 <? xml version="1.0" encoding="utf-8" ...
- android学习七(创建自己定义控件)
前面学习的是android的基本控件和布局的使用,可是主要的控件和布局有时候并不能实现复杂的布局.我们来看下各种控件和布局的关系. 可见全部的控件都是直接或者间接的继承自View的,全部的布局都是直接 ...
- Android自己定义控件系列五:自己定义绚丽水波纹效果
尊重原创!转载请注明出处:http://blog.csdn.net/cyp331203/article/details/41114551 今天我们来利用Android自己定义控件实现一个比較有趣的效果 ...
随机推荐
- 桶排序Bucket sort(转)
补充说明三点 1,桶排序是稳定的 2,桶排序是常见排序里最快的一种,比快排还要快…大多数情况下 3,桶排序非常快,但是同时也非常耗空间,基本上是最耗空间的一种排序算法 我自己的理解哈,可能与网上说的有 ...
- Android自定义Dialog多选对话框(Dialog+Listview+CheckBox)
先放效果截图 项目中需要有个Dialog全选对话框,点击全选全部选中,取消全选全部取消.下午查了些资料,重写了一下Dialog对话框.把代码放出来. public class MainActivity ...
- Sprak RDD简单应用
来自:http://my.oschina.net/scipio/blog/284957#OSC_h5_11 目录[-] 1.准备文件 2.加载文件 3.显示一行 4.函数运用 (1)map (2)co ...
- sprintf 心得
[string print format]sprintf指的是字符串格式化命令. [主要功能]是把格式化的数据写入某个字符串中. sprintf是个变参函数. 使用sprintf对于写入buffer的 ...
- Codeforces 743D Chloe and pleasant prizes(树型DP)
D. Chloe and pleasant prizes ...
- 1219 骑士游历(棋盘DP)
1997年 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如 ...
- SQLite的Pragma语句
SQLite的Pragma语句 Pragma语句是SQLite提供的特有语句.该语句可以查询SQLite的非表数据,还可以修改SQLite的库.在iOS开发中,利用Pragma语句,可以实现很多非 ...
- 平衡树之非旋Treap
平衡树(二叉树) 线段树不支持插入or删除一个数于是平衡树产生了 常见平衡树:treap(比sbt慢,好写吧),SBT(快,比较好写,有些功能不支持),splay(特别慢,复杂度当做根号n来用,功能强 ...
- 2.搭建配置最简单的spring mvc 工程-基础版
目标:用最少的东西,搭建可以运行的最最基础的springMvc登陆校验项目! spring 4 1.首先配置pom.xml引入spring 相关jar, 引用都有注释, 无关的可以暂时不引用. < ...
- php分页显示文章列表
<div class="content"> <ul> <?php $querySel = "select * from news where ...