Flexible banner base on RecyclerView
fir.im rxbanner_demo.apk
github rxbanner_demo.apk
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.leveychen:RxBanner:1.1.4'
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'
}
}
}
}
see Attributes
<cn.levey.bannerlib.RxBanner
android:id="@+id/rx_banner"
android:layout_width="match_parent"
android:layout_height="160dp"/>
banner = findViewById(R.id.rx_banner);
banner
.setLoader(new ImageLoader()) // see `image loader`
.setConfig(config) // see `config`
.setDatas(iamgesUrls, titles)
.start();
Fresco Glide Picasso UniversalImageLoader
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()
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 for Activity or Fragment and other views
banner.onResume()
banner.onPause()
banner.onDestroy()
RxBannerConfig
.getInstance()
.setDebug(true) // debug: default false
.setScrollStateChangedListener(new RxBannerScrollStateChangedListener()
.setLoader(new RxBannerImageViewLoader())
.setOrientation(LinearLayout.HORIZONTAL)
.setOrderType(RxBannerConfig.OrderType.ASC)
.setTimeInterval(5000);
just custom layout
for better performance
banner:rb_infinite="false"
banner:rb_autoPlay="false"
then
banner.setOnGuideFinishedListener(new RxBannerGuideFinishedListener()
onGuideFinished()
// todo
all done
All the rb_
attributes here are specific for RxBanner
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 |
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 |
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 |
forked from PageIndicatorView
Name | Attributes | Preview |
---|---|---|
AnimationType.NONE |
none |
![]() |
AnimationType.COLOR |
color |
![]() |
AnimationType.SCALE |
scale |
![]() |
AnimationType.SCALE_DOWN |
scale_down |
![]() |
AnimationType.SLIDE |
slide |
![]() |
AnimationType.WORM |
worm |
![]() |
AnimationType.FILL |
fill |
![]() |
AnimationType.THIN_WORM |
thin_worm |
![]() |
AnimationType.DROP |
drop |
![]() |
AnimationType.SWAP |
swap |
![]() |
AnimationType.NUMERIC |
numeric |
1/8 |
AnimationType.NUMERIC_CIRCLE |
numeric_circle |
(1/8) |
AnimationType.CUSTOM |
custom |
see CircleIndicator |
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"/>
-keep class cn.levey.bannerlib.** {
*;
}
See release notes on Github Releases
ViewPagerLayoutManager PageIndicatorView CircleIndicator
Apache-2.0. See LICENSE for detail