Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Latest commit

 

History

History
275 lines (220 loc) · 10.9 KB

README_EN.md

File metadata and controls

275 lines (220 loc) · 10.9 KB

RxBanner

API Apache 2.0 License

Flexible banner base on RecyclerView

中文文档   English

Demo Apk

fir.im      rxbanner_demo.apk

github      rxbanner_demo.apk

Preview

    

    

Integration

Step 1. Add it in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Step 2. Add the dependency     

    implementation 'com.github.leveychen:RxBanner:1.1.4'

LATEST RELEASE

dependencies failed

app.gradle

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.1'
            }
        }
    }
}

Usage

layout

see Attributes

    <cn.levey.bannerlib.RxBanner
        android:id="@+id/rx_banner"
        android:layout_width="match_parent"
        android:layout_height="160dp"/>

java

    banner = findViewById(R.id.rx_banner);
    banner
        .setLoader(new ImageLoader())               // see `image loader`
        .setConfig(config)                          // see `config`
        .setDatas(iamgesUrls, titles)
        .start();

image loader

Fresco     Glide     Picasso     UniversalImageLoader

config - optional

custom your config, the priority is higher than the xml

    RxBannerConfig config = banner.getConfig();
    config.set(value);
    ...
    banner.setConfig(config);
    banner.start();

you MUST set config before setDatas() and start()

listener - optional

    banner.setOnBannerClickListener(new RxBannerClickListener())
        onItemClick(int position, Object data)
        onItemLongClick(int position, Object data)

    banner.setOnBannerTitleClickListener(new RxBannerTitleClickListener())
        onTitleClick(int position, String title)

    banner.setOnBannerChangeListener(new RxBannerChangeListener())
        onBannerSelected(int position)
        onBannerScrollStateChanged(int state)

    banner.setOnGuideFinishedListener(new RxBannerGuideFinishedListener()
        onGuideFinished()

lifecycle

lifecycle for Activity or Fragment and other views

    banner.onResume()
    banner.onPause()
    banner.onDestroy()

Global Settings - optional

    RxBannerConfig
        .getInstance()
        .setDebug(true)  // debug: default false
        .setScrollStateChangedListener(new RxBannerScrollStateChangedListener()
        .setLoader(new RxBannerImageViewLoader())
        .setOrientation(LinearLayout.HORIZONTAL)
        .setOrderType(RxBannerConfig.OrderType.ASC)
        .setTimeInterval(5000);

Guide View

just custom layout

activity_guide.xml

for better performance

    banner:rb_infinite="false"
    banner:rb_autoPlay="false"

then

    banner.setOnGuideFinishedListener(new RxBannerGuideFinishedListener()
        onGuideFinished()
        // todo

all done

Attributes

All the rb_ attributes here are specific for RxBanner

Banner

Attributes format default description
rb_autoPlay boolean true auto play with rb_timeInterval delay
rb_infinite boolean true infinite loop, if false
rb_canSwipe boolean true can swipe manually or not
rb_canSwipeWhenSingle boolean true can swipe manually or not when only one image
rb_aspectRatio float / should be greater than 0, android:layout_height NOT be wrap_content or match_parent. recommend 1dp
rb_timeInterval integer (millisecond) 5000 for better performance, rb_timeInterval should be greater than 200 millisecond
rb_orientation horizontal / vertical horizontal layout orientation
rb_itemPercent integer 100 item width or height percentage
rb_itemScale float 1 banner item scale
rb_itemSpace dimension 0 banner item space
rb_centerAlpha float 1 center item alpha
rb_sideAlpha float 1 side item alpha
rb_itemMoveSpeed float 1 fling speed
rb_flingDamping float 1 fling damping
rb_orderType asc / desc asc /
rb_viewPaperMode boolean true one fling one paper like ViewPaper
rb_emptyViewText string 'No Banner' display when data is empty and 'rb_emptyViewResource' not define
rb_emptyViewResource reference / display when data is empty

Title

Attributes format default description
rb_title_visible boolean true view visibility
rb_title_gravity gravity START text gravity
rb_title_layout_gravity gravity CENTER_HORIZONTAL and BOTTOM layout gravity
rb_title_margin dimension 0dp margin
rb_title_padding dimension 3dp padding
rb_title_width dimension / enum MATCH_PARENT /
rb_title_height dimension / enum WRAP_CONTENT /
rb_title_size dimension 14sp /
rb_title_color color Color.WHITE /
rb_title_backgroundColor color #55000000 /
rb_title_backgroundResource reference / /
rb_title_marquee boolean true /
rb_title_lineSpacingMultiplier float 1.0f lineSpacingMultiplier

Indicator

Attributes format default description
rb_indicator_visible boolean true view visibility
rb_indicator_clickable boolean true click position to change banner selection
rb_indicator_orientation horizontal / vertical horizontal layout orientation
rb_indicator_layout_gravity gravity BOTTOM / END layout gravity
rb_indicator_radius dimension 5dp indicator radius
rb_indicator_textSize dimension 14sp numeric numeric_circle only
rb_indicator_textColor color Color.WHITE numeric numeric_circle only
rb_indicator_backgroundColor color / numeric numeric_circle only
rb_indicator_backgroundResource reference / numeric numeric_circle only
rb_indicator_scale float 0.7 scale or scale_down only
rb_indicator_margin dimension 8dp margin
rb_indicator_padding dimension 3dp padding
rb_indicator_selected_color color #FFFFFF /
rb_indicator_unselected_color color #33FFFFFF /
rb_indicator_interactiveAnimation boolean false /
rb_indicator_animationDuration integer 350 millisecond
rb_indicator_animationType type none see AnimationType
rb_indicator_rtl_mode on / off / auto auto support
rb_indicator_selectedResource reference / custom only,see CircleIndicator
rb_indicator_unselectedResource reference / custom only,see CircleIndicator
rb_indicator_animatorResource reference / custom only,see CircleIndicator
rb_indicator_animatorReverseResource reference / custom only,see CircleIndicator

AnimationType

forked from PageIndicatorView

Name Attributes Preview
AnimationType.NONE none anim_none
AnimationType.COLOR color anim_color
AnimationType.SCALE scale anim_scale
AnimationType.SCALE_DOWN scale_down anim_swap
AnimationType.SLIDE slide anim_slide
AnimationType.WORM worm anim_worm
AnimationType.FILL fill anim_worm
AnimationType.THIN_WORM thin_worm anim_thin_worm
AnimationType.DROP drop anim_drop
AnimationType.SWAP swap anim_swap
AnimationType.NUMERIC numeric 1/8
AnimationType.NUMERIC_CIRCLE numeric_circle (1/8)
AnimationType.CUSTOM custom see CircleIndicator

Permission

display images from network

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Proguard

    -keep class cn.levey.bannerlib.** {
        *;
    }

Release Note

See release notes on Github Releases

Thanks

ViewPagerLayoutManager PageIndicatorView CircleIndicator

License

Apache-2.0. See LICENSE for detail