zoukankan      html  css  js  c++  java
  • 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();
        }
  • 相关阅读:
    题解 [CF891C] Envy
    题解 [BZOJ4710] 分特产
    题解 [BZOJ2159] Crash的文明世界
    题解 [BZOJ4144] Petrol
    #leetcode刷题之路1-两数之和
    week 7 文件操作与模板
    coursera 北京大学 程序设计与算法 专项课程 STL week8 list
    coursera 北京大学 程序设计与算法 专项课程 完美覆盖
    JSTL标签库不起作用的解决方案 .(转)
    javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext解决办法(转)
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7207239.html
Copyright © 2011-2022 走看看