Android自定義封裝banner組件
自定義封裝 banner 組件,供大家參考,具體內(nèi)容如下
1. 效果圖預(yù)覽
2.基本功能
一個(gè)簡(jiǎn)單方便的輪播圖組件,基于viewpager 基礎(chǔ)上進(jìn)行的封裝。
可設(shè)置 項(xiàng)目中圖片,網(wǎng)絡(luò)圖片, View;
支持循環(huán)自動(dòng)播放,手勢(shì)滑動(dòng)切換,item點(diǎn)擊事件,可設(shè)置 點(diǎn)點(diǎn)的樣式寬高、顏色、大小、位置 ;
可設(shè)置蒙層;可設(shè)置 是否允許滑動(dòng);可設(shè)置 是否允許循環(huán)。
3.基本實(shí)現(xiàn)
1). 自定義屬性
<declare-styleable name="BannerLayoutStyle"> <attr name="maskStartColor" format="color|reference" /> <attr name="maskEndColor" format="color|reference" /> <attr name="selectedIndicatorColor" format="color|reference" /> <attr name="unSelectedIndicatorColor" format="color|reference" /> <attr name="indicatorShape" format="enum"> <enum name="rect" value="0" /> <enum name="oval" value="1" /> </attr> <attr name="selectedIndicatorHeight" format="dimension|reference" /> <attr name="selectedIndicatorWidth" format="dimension|reference" /> <attr name="unSelectedIndicatorHeight" format="dimension|reference" /> <attr name="unSelectedIndicatorWidth" format="dimension|reference" /> <attr name="indicatorPosition" format="enum"> <enum name="centerBottom" value="0" /> <enum name="rightBottom" value="1" /> <enum name="leftBottom" value="2" /> <enum name="centerTop" value="3" /> <enum name="rightTop" value="4" /> <enum name="leftTop" value="5" /> </attr> <attr name="indicatorSpace" format="dimension|reference" /> <attr name="indicatorMargin" format="dimension|reference" /> <attr name="autoPlayDuration" format="integer|reference" /> <attr name="scrollDuration" format="integer|reference" /> <attr name="isAutoPlay" format="boolean" /> <attr name="defaultImage" format="integer|reference" /> <attr name="isIndicatorVisible" format="boolean" /> <attr name="cornerRadii" format="dimension|reference" /> </declare-styleable>
2).基本方法
//添加本地圖片路徑 public void setViewRes(List<Integer> viewRes) {。。。} //添加網(wǎng)絡(luò)圖片路徑 public void setViewUrls(List<String> urls) {。。。} //添加任意View視圖 private void setViews2(final List<View> views) {。。。}
// 設(shè)置是否允許 循環(huán) public void setLoop(boolean loop) { } // 設(shè)置是否可以滑動(dòng) public void setSlideable(boolean slideable) { }
更多用法 詳見代碼,這里就不全部粘貼了。
3).使用示例:
<com.dzq.widget.CustomBannerView android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" app:autoPlayDuration="2000" app:defaultImage="@drawable/bg_banner" app:indicatorMargin="@dimen/indicatorMargin" app:indicatorPosition="rightBottom" app:indicatorShape="oval" app:indicatorSpace="@dimen/indicatorSpace" app:isAutoPlay="true" app:isIndicatorVisible="true" app:scrollDuration="1000" app:selectedIndicatorColor="@color/color_ec407a" app:selectedIndicatorHeight="5dp" app:selectedIndicatorWidth="5dp" app:unSelectedIndicatorColor="@color/color_71d9e7" app:unSelectedIndicatorHeight="5dp" app:unSelectedIndicatorWidth="5dp" /> <com.dzq.widget.CustomBannerView android:id="@+id/banner2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_weight="1" app:autoPlayDuration="2000" app:defaultImage="@drawable/bg_banner" app:indicatorMargin="@dimen/indicatorMargin" app:indicatorPosition="rightBottom" app:indicatorShape="rect" app:indicatorSpace="@dimen/indicatorSpace" app:isAutoPlay="false" app:isIndicatorVisible="true" app:scrollDuration="1000" app:selectedIndicatorColor="@color/color_ec407a" app:selectedIndicatorHeight="5dp" app:selectedIndicatorWidth="10dp" app:unSelectedIndicatorColor="@color/color_71d9e7" app:unSelectedIndicatorHeight="10dp" app:unSelectedIndicatorWidth="5dp" /> <com.dzq.widget.CustomBannerView android:id="@+id/banner3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_weight="1" app:cornerRadii="5dp" app:indicatorMargin="@dimen/indicatorMargin" app:indicatorPosition="centerTop" app:indicatorShape="rect" app:indicatorSpace="@dimen/indicatorSpace" app:isAutoPlay="false" app:isIndicatorVisible="true" app:maskEndColor="#00000000" app:maskStartColor="#99000000" app:scrollDuration="1000" app:selectedIndicatorColor="#00CAA9" app:selectedIndicatorHeight="10dp" app:selectedIndicatorWidth="25dp" app:unSelectedIndicatorColor="#26000000" app:unSelectedIndicatorHeight="10dp" app:unSelectedIndicatorWidth="10dp" />
項(xiàng)目源碼下載
導(dǎo)入自己項(xiàng)目
How to
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
Step 2. Add the dependency
dependencies { compile 'com.github.dingzuoqiang:CustomBannerView:v1.0' }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
android dialog邊框去除白色邊框?qū)崿F(xiàn)思路及代碼
android dialog邊框含有白色真是美中不足啊,本文將介紹如何去除白色邊框,有思路及代碼,感興趣的朋友可以了解下2013-01-01Android開發(fā)listview選中高亮簡(jiǎn)單實(shí)現(xiàn)代碼分享
這篇文章主要介紹了Android開發(fā)listview選中高亮簡(jiǎn)單實(shí)現(xiàn)代碼分享,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01系統(tǒng)應(yīng)用根據(jù)Uri授予權(quán)限方法詳解
這篇文章主要為大家介紹了系統(tǒng)應(yīng)用根據(jù)Uri授予權(quán)限方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Android實(shí)現(xiàn)購(gòu)物車添加商品動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)購(gòu)物車添加商品動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06Android permission denied原因歸納和解決辦法
大家好,本篇文章主要講的是Android permission denied原因歸納和解決辦法,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下哦2021-12-12Android基礎(chǔ)知識(shí)之frame動(dòng)畫效果
Android基礎(chǔ)知識(shí)之tween動(dòng)畫效果,Android一共提供了兩種動(dòng)畫,這篇文章主要介紹了Android動(dòng)畫效果之frame動(dòng)畫,感興趣的小伙伴們可以參考一下2016-06-06Android自定義View實(shí)現(xiàn)QQ音樂中圓形旋轉(zhuǎn)碟子
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)QQ音樂中圓形旋轉(zhuǎn)碟子,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Android實(shí)現(xiàn)類似360,QQ管家那樣的懸浮窗
用到的就是WindowManager以及WindowManager.LayoutParams,對(duì)這個(gè)LayoutParams做文章,當(dāng)設(shè)置為屬性后,然后,創(chuàng)建一個(gè)View,將這個(gè)View添加到WindowManager中就行2013-06-06Android自定義扇形倒計(jì)時(shí)實(shí)例代碼
最近工作中需要做一個(gè)倒計(jì)時(shí),是那種一個(gè)圓,慢慢的被吃掉的動(dòng)畫倒計(jì)時(shí),由于自己是android小白,效果還不是多滿意,先給大家分享實(shí)例代碼,僅供大家參考2017-03-03