BillBoardView自定义控件广告板轮播
来源:互联网 发布:道琼斯指数行情软件 编辑:程序博客网 时间:2024/05/01 23:57
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:是不是自动播放,不需要滑动,默认trueisLoopIt:是不是无限循环播放,默认是trueintervalTime:播放间隔时间,每隔多长时间走一页
构建实体
//实体类实现获取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)//获取内部的ViewPagerpublic 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 = 2public void setTitleGravity(int gravity)//设置导航栏的位置POS_LEFT = 0, POS_CENTER = 1, POS_RIGHT = 2public void setGuideLyGravity(int gravity)
如何自定义Adapter
//Adapter做的工作是,覆盖在BillBoardView上面,随着BillBoardView的变化,修改UIpublic 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(); }
0 0
- BillBoardView自定义控件广告板轮播
- Android自定义控件之广告视图
- Android自定义控件---广告条滚动
- android自定义控件之滚动广告条
- android自定义控件之滚动广告条
- 自定义控件--广告条(ViewPager)
- 自定义控件(二)--广告轮播
- iOS 自定义无限循环滚动广告动画控件
- 自定义控件:使用ViewPager实现广告条效果
- Android自定义控件BannerLayout,实现广告轮播
- 广告控件
- 自定义广告
- android 自定义ViewFlipper轮播广告控件——自定义控件学习(二)
- android 自定义ViewAnimator文字轮播广告控件——自定义控件学习(三)
- android 自定义轮播广告控件ViewPager——自定义控件学习(四)
- iOS开发系列之常用自定义控件开发集—自动广告墙图片控件开发
- Android自定义控件显示多页图片展示效果并自动翻页适合广告展示
- Android自定义控件——仿淘宝、网易、彩票等广告条、Banner的制作
- *hdu1078(记忆化搜索)
- xdotool源代码,需要的伙伴请自取
- JDBC知识 - 马士兵视频教程笔记
- 矩形覆盖
- 在Java中使用Sqlite数据库
- BillBoardView自定义控件广告板轮播
- 针对于分布式平台hadoop取数据的两种方式
- 解决Myeclipse服务器Servers视图下不显示tomcat解决: 1. 关闭Myeclipse 2. 去workspace中删除 com.genuitec.eclipse.ast.deploy
- 二进制中1的个数
- POJ 2492 A Bug's Life 并查集
- win8 vc++编译的程序在XP系统运行报错。一个警告标志(黄色三角形里面一个感叹号)
- 合并两个排序的链表
- 使用U盘+iso镜像文件安装windows10操作系统详细步骤
- Session and cookie