Coder Social home page Coder Social logo

bannerview's Introduction

a simple BannerView which can auto switch pages based on ViewPager and LinearLayout.

update 如果Banner图片为2张,则需要改变一下setViewList的策略(将new ImageView的步骤移至此处,clicklistener也同理)
    public void setViewList(List<YourImageBean> viewList) {
        this.viewList = viewList;
        if (viewList != null && viewList.size() != 0) {
            viewSize = viewList.size();
            if (viewSize == 2) {
                viewList.add(viewList.get(0));
                viewList.add(viewList.get(1));
            }
        }
        List<View> imageViews = new ArrayList<>();
        for (int i = 0; i < viewList.size(); i++) {
            ImageView image = new ImageView(getContext());
            image.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        //设置显示格式
            image.setScaleType(ImageView.ScaleType.FIT_XY);
            image.setImageResource(viewList.get(i));
            imageViews.add(image);
        }
        BannerAdapter bannerAdapter = new BannerAdapter(imageViews);
        setAdapter(bannerAdapter);
    }
update 2017-08-24 解决了从其他界面返回后banner轮播混乱的问题
  • dependencies(依赖)
compile 'com.coldmoqiuli:banners:1.0.1'
  • useage(传递进一个List,如需listener,clicklistener也在创建ImageView的时候自行处理好即可)
        bannerView = (BannerView) findViewById(R.id.banner);
        bannerView.setViewList(viewList);
        bannerView.startLoop(true);
  • like this

screenshot

bannerview's People

Contributors

byblinkdagger avatar

Watchers

James Cloos 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.