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. CodeForces - 361E Levko and Strings

    Discription Levko loves strings of length n, consisting of lowercase English letters, very much. He ...

  2. [SPOJ7001]VLATTICE - Visible Lattice Points

    题目大意: $q(q\leq50)$组询问,对于给定的$n(n\leq10^7)$,求$\displaystyle\sum_{i=0}^n\sum_{j=0}^n\sum_{k=0}^n[\gcd(i ...

  3. 转:Maven项目中获取classpath和资源文件的路径

    假设资源文件放在maven工程的 src/main/resources 资源文件夹下,源码文件放在 src/main/java/下, 那么java文件夹和resources文件夹在运行时就是class ...

  4. Maven错误“Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create ”解决

    用maven3新建一个项目时,输入的命令如下: mvn archetype:create 出现错误如下: [ERROR] Failed to execute goal org.apache.maven ...

  5. WPF 自动验证

    WPF中TextBox的自动验证: 演示 : 用以下两个TextBox分别显示验证IP和非空值验证,先看效果: IP自动验证效果: 非空值自动验证效果: 第一步:定义TextBox验证的样式: < ...

  6. JavaScript 深克隆

    深克隆 function judgeType(arg){//判断js数据类型 return Object.prototype.toString.call(arg).slice(8,-1); } fun ...

  7. 关于AutoLayout(自动布局)那些事儿

    这是博主的WWDC2012笔记系列中的一篇,完整的笔记列表可以参看这里.如果您是首次来到本站,也许您会有兴趣通过RSS,或者通过页面左侧的邮件订阅的方式订阅本站. AutoLayout在去年的WWDC ...

  8. 查看linux 系统 当前使用的网卡

    使用ifconfig命令查看到linux 系统有三个网卡 ,其实我只要其中一个启用就可以了,用什么命令查看或者切换网卡,或者停用掉其他两个网卡? watch cat /proc/net/dev 看下哪 ...

  9. CSS属性clip

    http://blog.sina.com.cn/s/blog_68a1582d0100kp59.html CSS属性中有个裁剪属性clip,其实我对这个属性一点都不感冒,因为我感觉它好像没啥用处,但是 ...

  10. ylb:SQL 存储过程(Procedure)

    ylbtech-SQL Server: SQL Server-SQL 存储过程(Procedure) 1,存储过程(Procedure)-基本创建与操作 2,存储过程(Procedure)-入参 3, ...