GithubHelp home page GithubHelp logo

bannery's Introduction

BannerY

原理介绍

属性介绍

属性 解释
point_size 指示器大小
point_bg 指示器背景
point_bottom_margin 指示器距离底边距离
desc_bottom_margin 文字描述距离底边距离
desc_color 文字描述的文字颜色
desc_size 文字描述的文字大小
banner_interval 切换图片间隔时间
banner_im_scaletype 图片缩放类型
banner_size_sclae 图片两边增加Padding,一个页面可以看到3张Banner图

依赖

// 1.
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
// 2.
dependencies {
    // 将TAG替换为最新的版本号,例如 implementation 'com.github.rgdzh1:BannerY:0.2.8'
    implementation 'com.github.rgdzh1:BannerY:TAG'
}

XML布局使用

<com.yey.library_banner.BannerY
    android:id="@+id/banner"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:banner_interval="2000"
    app:banner_scaletype="centerInside"
    app:desc_bottom_margin="10dp"
    app:desc_color="@color/colorAccent"
    app:desc_size="18sp"
    app:point_bottom_margin="10dp"
    app:point_bg="@drawable/point_bg"
    app:point_size="8dp" />

#### 指示器背景资源 point_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:drawable="@drawable/point_normal"/>
    <item android:state_enabled="true" android:drawable="@drawable/point_press"/>
</selector>

#### point_press.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size
        android:width="8dp"
        android:height="8dp" />
    <solid android:color="@color/colorAccent"/>
</shape>

#### point_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size
        android:width="8dp"
        android:height="8dp" />
    <solid android:color="@color/colorPrimary"/>
</shape>

代码设置

// 从链接获取图片
bannerY2 = (BannerY) findViewById(R.id.banner2);
ArrayList<String> urlList = new ArrayList<>();
ArrayList<String> descList = new ArrayList<>();
descList.add("第1链接");
descList.add("第2链接");
descList.add("第3链接");
descList.add("第4链接");
urlList.add("https://ww4.sinaimg.cn/bmiddle/005QVDzfly1g9bmtlo07jj30go0gp43w.jpg");
urlList.add("https://ww4.sinaimg.cn/bmiddle/005QVDzfly1g9bmtmaglhj30go0gp77x.jpg");
urlList.add("https://ww4.sinaimg.cn/bmiddle/005QVDzfly1g9bmtmmrofj30go0gpaen.jpg");
urlList.add("https://ww1.sinaimg.cn/bmiddle/005QVDzfly1g9bmtk204sj30go0gpjva.jpg");
bannerY2.setImagesRes(urlList);
bannerY2.setDescList(descList);
bannerY2.setClickBanner(new IClickBanner() {
    @Override
    public void click(int i) {
        Toast.makeText(MainActivity.this, i + "bannerY2 被点击", Toast.LENGTH_LONG).show();
    }
});
// 从资源id获取图片
bannerY = (BannerY) findViewById(R.id.banner);
ArrayList<Integer> integers = new ArrayList<>();
ArrayList<String> strings = new ArrayList<>();
strings.add("111111111");
strings.add("222222222");
strings.add("333333333");
strings.add("444444444");
integers.add(R.mipmap.banner_1);
integers.add(R.mipmap.banner_2);
integers.add(R.mipmap.banner_3);
integers.add(R.mipmap.banner_4);
bannerY.setImagesRes(integers);
bannerY.setDescList(strings);
bannerY.setClickBanner(new IClickBanner() {
    @Override
    public void click(int i) {
        Toast.makeText(MainActivity.this, i + "bannerY 被点击", Toast.LENGTH_LONG).show();
    }
});

DEMO下载

bannery's People

Contributors

koala0x 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.