Git Product home page Git Product logo

banner-2's Introduction

BannerViewPager

License Download

轮播图控件

预览

1.用法

Android Studio使用依赖:

compile 'cn.kevin:bannerview:1.0.6'

或者下载工程后使用

compile project(':banner')

2.功能

  • 实现广告轮播,通过设置参数,可以实现当前item、前一个、后一个同时显示的效果。

3.属性

自定义属性 含义
marginLeft 中心item距离整体控件左侧距离
marginRight 中心item距离整体控件右侧距离
item_margin item与item的间距
around_visible 是否露出上一个和下一个item, 默认为true
point_drawable 页索引的drawle,默认为圆点, 为selector, 通过state_selected区分选中状态
point_gravity 页索引的显示位置,默认为bottom_center

4.代码演示 也可参考demo中的代码

1.在布局文件中加入BannerViewPager

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/viewPagerContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <kevinmob.banner.BannerViewPager
        android:id="@+id/bvp"
        android:layout_width="200dp"
        android:layout_height="100dp"
        android:layout_marginTop="30dp"
        android:layerType="software"
        app:item_margin="20dp"
        app:marginLeft="40dp"
        app:marginRight="40dp"
        app:point_gravity="bottom_center" />
    </FrameLayout>

2.在java中设置数据

    bannerViewPager = (BannerViewPager) findViewById(R.id.bvp);
	
    BannerAdapter adapter = new BannerAdapter();
    //item需要实现IBannerItem接口
    List<IBannerItem> list = new ArrayList<>();
    adapter.setData(context, list);

    adapter.setImageLoader(new GlideImageLoader());
    bannerViewPager.setBannerAdapter(adapter);
    bannerViewPager.setBannerItemClick(new BannerViewPager.IBannerItemClick() {
        @Override
        public void onClick(IBannerItem data) {
            Toast.makeText(MainActivity.this, " data.ImageUrl() " + data.ImageUrl(), Toast.LENGTH_SHORT).show();
        }
    });

    //这里举例为Glide,实际使用时需配合自己项目中的图片加载框架完成图片加载
    class GlideImageLoader implements ImageLoader {
        @Override
        public void onDisplayImage(Context context, ImageView imageView, String url) {
        Glide.with(context).load(url).into(imageView);
        }
    }

banner-2's People

Contributors

kevin-mob avatar

Watchers

 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.