支持圖片無限輪播的BannerLayout
RecyclerView Banner
利用RecyclerView
實現(xiàn)的Banner輪播
代碼示例:
https://github.com/7449/BannerLayout(https://github.com/7449/BannerLayout)
BannerLayout
支持圖片無限輪播的BannerLayout
支持功能
- 功能較多葵蒂,很多功能都已添加鬓椭,建議下載sample ,查看代碼
支持動態(tài)更新數(shù)據(jù)
可自定義小圓點,title,提示欄位置趴酣,支持自定義selector選擇器
支持 Banner 為 ListView 或 RecyclerView 的 Header 欢峰,滑動時且不影響B(tài)anner的滾動
可自定義是否自動輪播,輪播時間
支持點擊事件以及輪播速度及viewPager滑動切換速度
支持是否顯示小圓點,title,或者整個提示欄
支持加載時和加載失敗時顯示自定義圖片
支持選擇暫停 恢復(fù) 輪播狀態(tài)
支持動畫以及垂直滾動
使用效果
- 如果加載失敗請移步至GitHub主頁查看
基礎(chǔ)使用方法
gradle
compile 'com.ydevelop:bannerlayout:1.1.1'
maven
<dependency>
<groupId>com.ydevelop</groupId>
<artifactId>bannerlayout</artifactId>
<version>1.1.1</version>
<type>pom</type>
</dependency>
建議先看一下示例 : SimpleActivity
如果是網(wǎng)絡(luò)加載圖片 記得添加
<uses-permission android:name="android.permission.INTERNET" />
簡單使用方式
Bean類請實現(xiàn) BannerModelCallBack
具體可參考 SimpleBannerModel
如果讓BannerLayout
實現(xiàn)圖片的加載記得依賴Glide
compile 'com.github.bumptech.glide:glide:3.7.0'
或者實現(xiàn)ImageLoaderManager
public class SimpleManager implements ImageLoaderManager<SimpleBannerModel> {
@NonNull
@Override
public ImageView display(@NonNull ViewGroup container, SimpleBannerModel model) {
ImageView imageView = new ImageView(container.getContext());
// picasso or fresco or universalimageloader
return imageView;
}
}
簡易實現(xiàn):
banner
.initListResources(data)
//if you use glide this step is not necessary
.setImageLoaderManager(new SimpleImageManager())
.switchBanner(true/false);
垂直滾動
banner
.setVertical(true)
PageChangeListener
banner
.addOnPageChangeListener(
new OnBannerChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
點擊事件
如果不傳遞泛型纽帖,返回的model就是當(dāng)前Bean類宠漩,強轉(zhuǎn)即可,建議傳遞泛型
banner
.setOnClickListener(
new OnBannerClickListener<SimpleBannerModel>() {
@Override
public void onBannerClick(View view, int position, SimpleBannerModel model) {
}
});
提示欄及小圓點懊直、title位置的改變
setTipsSite() 提示欄在布局中的位置扒吁,top,bottom,center三種可選
setDotsSite() 小圓點在提示欄的位置,left,center,right三種可選
setTitleSite() title在提示欄的位置室囊,left,center,right三種可選
xml:
<com.bannerlayout.widget.BannerLayout
...
app:tips_site="center" />
切換動畫以及速度
viewpager的垂直這里用的是動畫雕崩,所以只要選擇了垂直滾動,設(shè)置動畫無效
動畫內(nèi)置的 ViewPagerTransforms融撞,多謝作者
如果想自定義動畫請繼承 ABaseTransformer 或者 BannerTransformer 即可;
setBannerTransformer(BannerLayout.ANIMATION_CUBE_IN)
或者
setBannerTransformer(new ZoomOutSlideTransformer())
動畫集合:
自定義動畫集合
Integer: 0 ~ 17
List<Integer> integerList = new ArrayList<>();
setBannerSystemTransformerList(transformers);
系統(tǒng)動畫集合
List<BannerTransformer> bannerTransformer = new ArrayList<>();
etBannerSystemTransformerList(bannerTransformer);
java 方法
see: MethodTestActivity
newBannerLayout
.setDelayTime(3000)
.setErrorImageView(R.mipmap.ic_launcher)
.setPlaceImageView(R.mipmap.ic_launcher)
.setDuration(3000)
.setViewPagerTouchMode(true)
.setVertical(true)
.setTitleTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark))
.setTitleTextSize(23)
.setTipsBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent))
.setTipsDotsSelector(R.drawable.banner)
.setTipsWidthAndHeight(BannerLayout.MATCH_PARENT, 300)
.setTipsSite(BannerLayout.TOP)
.setTitleMargin(60, 20)
.setTitleSite(BannerLayout.LEFT)
.setDotsWidthAndHeight(30, 30)
.setDotsSite(BannerLayout.RIGHT)
.setNormalRadius(2)
.setNormalColor(ContextCompat.getColor(getApplicationContext(), R.color.colorYellow))
.setEnabledRadius(2)
.setEnabledColor(ContextCompat.getColor(getApplicationContext(), R.color.colorYellow))
.setDotsMargin(60, 60)
.setBannerTransformer(BannerLayout.ANIMATION_ZOOMOUT)
.setBannerTransformer(new ZoomOutSlideTransformer())
.setPageNumViewRadius(1)
.setPageNumViewMargin(10, 10, 10, 10)
.setPageNumViewPadding(10, 10, 10, 10)
.setPageNumViewMargin(10)
.setPageNumViewPadding(10)
.setPageNumViewTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorYellow))
.setPageNumViewBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent))
.setPageNumViewSite(BannerLayout.PAGE_NUM_VIEW_BOTTOM_CENTER)
.setPageNumViewTextSize(22)
.setPageNumViewMark(" & ")
.initPageNumView()
.initTips(true, true, true)
.setOnBannerClickListener(this)
.addOnPageChangeListener(this)
.initListResources(SimpleData.initModel())
.switchBanner(true);
xml 屬性
xml default parameter see:
app:banner_dots_visible="true"
app:banner_page_num_radius="2"
app:banner_page_num_paddingLeft="10"
app:banner_page_num_paddingTop="10"
app:banner_page_num_paddingRight="10"
app:banner_page_num_paddingBottom="10"
app:banner_page_num_marginTop="10"
app:banner_page_num_marginLeft="10"
app:banner_page_num_marginRight="10"
app:banner_page_num_marginBottom="10"
app:banner_page_num_textColor="@color/colorYellow"
app:banner_page_num_textSize="22sp"
app:banner_page_num_BackgroundColor="@color/colorYellow"
app:banner_page_num_mark="@string/app_name"
app:banner_pageNum_site="bottomRight"
app:banner_tips_site="bottom"
app:banner_dots_site="center"
app:banner_title_site="center"
app:banner_start_rotation="true"
app:banner_title_visible="true"
app:banner_title_size="10sp"
app:banner_title_color="@color/colorYellow"
app:banner_title_width="200"
app:banner_title_height="60"
app:banner_title_left_margin="60"
app:banner_title_right_margin="60"
app:banner_dots_left_margin="40"
app:banner_dots_right_margin="40"
app:banner_dots_width="30"
app:banner_dots_height="30"
app:banner_enabledRadius="2"
app:banner_enabledColor="@color/colorAccent"
app:banner_normalRadius="2"
app:banner_normalColor="@color/colorBackground"
app:banner_glide_error_image="@mipmap/ic_launcher"
app:banner_glide_place_image="@mipmap/ic_launcher"
app:banner_is_tips_background="true"
app:banner_tips_background="@color/colorAccent"
app:banner_tips_width="match_parent"
app:banner_tips_height="300"
app:banner_dots_selector="@drawable/banner"
app:banner_start_rotation="true"
app:banner_delay_time="300"
app:banner_duration="3000"
app:banner_view_pager_touch_mode="true"
License
Copyright (C) 2016 yuebigmeow@gamil.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.