Code Monkey home page Code Monkey logo

banner's Introduction

###如何使用

首先在gradle文件中添加

 compile 'com.xiwenhec:banner:1.0.5'

listView的实现习惯,增加了一个适配器,调用者只需要这样一下几步就可以完成: 第一步:在xml代码写入控件

   <com.sivin.Banner 
        android:id="@+id/id_banner"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        app:banner_pointGravity="right"
        />

  第二步:java代码中绑定控件

 mBanner = (Banner) findViewById(R.id.id_banner);

  第三步:实例化适配器,并设置适配器,建议您在new BannerAdapter<BannerModel>的时候将后面的<>中的泛型加上,然后在根据工具提示实现未完成的方法。这里你需要重写bindTips(TextView tv, BannerModel bannerModel)bindImage(ImageView imageView, BannerModel bannerModel)方法,方法的第二个参数就是你加入的泛型类型。其中mDatas你的banner的数据集合,具体过程使用就会有所体会。    注意:不要忘了mDatas的初始化,合理的做法应该这样的 private List<BannerModel> mDatas = new ArrayList<>();

  BannerAdapter adapter = new BannerAdapter<BannerModel>(mDatas) {
            @Override
            protected void bindTips(TextView tv, BannerModel bannerModel) {
                tv.setText(bannerModel.getTips());
            }

            @Override
            public void bindImage(ImageView imageView, BannerModel bannerModel) {
                Glide.with(mContext)
                        .load(bannerModel.getImageUrl())
                        .placeholder(R.mipmap.empty)
                        .error(R.mipmap.error)
                        .into(imageView);
            }

        };
 mBanner.setBannerAdapter(adapter);

  最后一步:告诉banner数据不部署完成,为什么这样做呢,正常情况下,我们的数据都是从网络上异步加载的,一般的情况下会以集合的形式传递过来,当我们在完成网络加载的时候,改变了mDatas数据,然后调用mBanner.notifiDataHasChanged();通知banner就行了,使用起来和listview的习惯是不是很相似呢,对就是这样

 mBanner.notifyDataHasChanged();

为了更加优美的控制banner控件,这里提供了很多可控制的属性,我们可以这样做:

    <com.sivin.Banner
        android:id="@+id/id_banner"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        app:banner_pointContainerLeftRightPadding="10dp"
        app:banner_pointTopBottomMargin="6dp"
        app:banner_pointLeftRightMargin="3dp"
        app:banner_pointGravity="right"
        app:banner_pointContainerBackground="#33000000"
        app:banner_pointDrawable="@drawable/selector_banner_point"
        app:banner_pointAutoPlayInterval="3"
        app:banner_pageChangeDuration="800"
        app:banner_tipTextColor="#FFFFFF"
        app:banner_tipTextSize="12sp"/>

banner's People

Contributors

xiwenhec avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.