BillBoardView自己定义控件广告板轮播
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:播放间隔时间,每隔多长时间走一页
构建实体
public class Demo implements BoardConfig{}
定义载入工具
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
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
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
public class MyAdapter extends BoardAdapter<Demo> {
public MyAdapter(Context mContext, List<Demo> datas) {
super(mContext, datas);
}
@Override
protected int getLayoutId() {
return 0;
}
@Override
protected void initAdapterViews() {
}
@Override
public void changeItemDisplay(int pos, Demo demo) {
}
@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();
}