自定義封裝 banner 組件

来源:http://www.cnblogs.com/dingzq/archive/2017/06/27/7085944.html
-Advertisement-
Play Games

1. 效果圖預覽 2.基本功能 3.基本實現 1. 自定義屬性 2.基本方法 更多用法 詳見代碼,這裡就不全部粘貼了。 3.使用示例: 項目源碼下載 導入自己項目 How to How to How to To get a Git project into your build: To get a ...


1. 效果圖預覽

 

 

2.基本功能

一個簡單方便的輪播圖組件,基於viewpager 基礎上進行的封裝。
可設置 項目中圖片,網路圖片, View;
支持迴圈自動播放,手勢滑動切換,item點擊事件,可設置 點點的樣式寬高、顏色、大小、位置 ,;
可設置蒙層;可設置 是否允許滑動;可設置 是否允許迴圈。

 

3.基本實現

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) {。。。}

   //添加網路圖片路徑
    public void setViewUrls(List<String> urls) {。。。}

    //添加任意View視圖
    private void setViews2(final List<View> views) {。。。}
    // 設置是否允許 迴圈
    public void setLoop(boolean loop) {

    }

    // 設置是否可以滑動
    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" />

 

項目源碼下載

導入自己項目

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'
    }

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 圓形 circle 矩形 rect 橢圓 ellipse 線 line 折線 polyline 多邊形 polygon 路徑 path 可用於路徑數據的命令 M = moveto L = lineto H = horizontal lineto V = vertical lineto C = cur ...
  • 1.SVG 是用XML格式定義的矢量圖。 2.文件體積小,能夠被大量的壓縮。 3.圖片可無限放大而不失真(矢量圖的基本特征)。 4.在視網膜顯示屏上效果極佳。 5.能夠實現互動和濾鏡效果。 6.svg元素里提供了“width”和“height”兩個屬性來定義SVG圖片的高度和寬度。 7.fill屬性 ...
  • 此文章是稍早前寫的,本次屬於文章遷移@2017.06.27 前言 俗話說“在js語言中,一切都對象”,而且創建對象的方式也有很多種,所以今天我們做一下梳理 最簡單的方式 JavaScript創建對象最簡單的方式是:對象字面量形式或使用Object構造函數 對象字面量形式 使用Object構造函數 明 ...
  • /^(0(?:[.](?:[1-9]\d?|0[1-9]))|[1-9]\d*(?:[.]\d{1,2}|$))$/ 不為0的正整數或帶1到2位小數的數字(以0打頭的則後面必須接小數點且小數點後面必然為01-99,以大於0的數打頭則小數可為1至2位任意數字或無小數部分.) ...
  • 1.設置佈局屬性: 2.BitmapUtils類-- 得到指定圓形的Bitmap對象 3.BitmapUtils類--壓縮圖片 4.根據user.getImageurl()顯示圓形圖像 ...
  • 轉自:http://www.cnblogs.com/daiweilai/p/4421340.html 侵刪 目錄 前言逼優雞知己知彼 百戰不殆抽刀斷Bug 普通操作 全局斷點(Global BreakPoint) 條件斷點(Condational Breakpoints)列印的藝術 NSLog 開啟 ...
  • 一、介紹 MVP(Model View Presenter)架構是從著名的MVC(Model View Controller)架構演變而來的。對於在Android應用中開發就可以視為是MVC架構,佈局文件視為View,Activity視為Controller,但是Activity還要控制佈局的更新, ...
  • 音樂播放器後臺之歌曲讀取 1.引言 & 160;& 160;& 160;& 160;C 中可以使用的第三方解決方案實在是不多,可以適用於UWP的解決方案就更少了。經過兩天的不懈努力,我算是基本上完成了讀取MP3文件中的標題、參與創作的藝術家、唱片集等信息,但是很遺憾,對MP3文件封面的讀取沒有實現。 ...
一周排行
    -Advertisement-
    Play Games
  • C#TMS系統代碼-基礎頁面BaseCity學習 本人純新手,剛進公司跟領導報道,我說我是java全棧,他問我會不會C#,我說大學學過,他說這個TMS系統就給你來管了。外包已經把代碼給我了,這幾天先把增刪改查的代碼背一下,說不定後面就要趕鴨子上架了 Service頁面 //using => impo ...
  • 委托與事件 委托 委托的定義 委托是C#中的一種類型,用於存儲對方法的引用。它允許將方法作為參數傳遞給其他方法,實現回調、事件處理和動態調用等功能。通俗來講,就是委托包含方法的記憶體地址,方法匹配與委托相同的簽名,因此通過使用正確的參數類型來調用方法。 委托的特性 引用方法:委托允許存儲對方法的引用, ...
  • 前言 這幾天閑來沒事看看ABP vNext的文檔和源碼,關於關於依賴註入(屬性註入)這塊兒產生了興趣。 我們都知道。Volo.ABP 依賴註入容器使用了第三方組件Autofac實現的。有三種註入方式,構造函數註入和方法註入和屬性註入。 ABP的屬性註入原則參考如下: 這時候我就開始疑惑了,因為我知道 ...
  • C#TMS系統代碼-業務頁面ShippingNotice學習 學一個業務頁面,ok,領導開完會就被裁掉了,很突然啊,他收拾東西的時候我還以為他要旅游提前請假了,還在尋思為什麼回家連自己買的幾箱飲料都要叫跑腿帶走,怕被偷嗎?還好我在他開會之前拿了兩瓶芬達 感覺感覺前面的BaseCity差不太多,這邊的 ...
  • 概述:在C#中,通過`Expression`類、`AndAlso`和`OrElse`方法可組合兩個`Expression<Func<T, bool>>`,實現多條件動態查詢。通過創建表達式樹,可輕鬆構建複雜的查詢條件。 在C#中,可以使用AndAlso和OrElse方法組合兩個Expression< ...
  • 閑來無聊在我的Biwen.QuickApi中實現一下極簡的事件匯流排,其實代碼還是蠻簡單的,對於初學者可能有些幫助 就貼出來,有什麼不足的地方也歡迎板磚交流~ 首先定義一個事件約定的空介面 public interface IEvent{} 然後定義事件訂閱者介面 public interface I ...
  • 1. 案例 成某三甲醫預約系統, 該項目在2024年初進行上線測試,在正常運行了兩天後,業務系統報錯:The connection pool has been exhausted, either raise MaxPoolSize (currently 800) or Timeout (curren ...
  • 背景 我們有些工具在 Web 版中已經有了很好的實踐,而在 WPF 中重新開發也是一種費時費力的操作,那麼直接集成則是最省事省力的方法了。 思路解釋 為什麼要使用 WPF?莫問為什麼,老 C# 開發的堅持,另外因為 Windows 上已經裝了 Webview2/edge 整體打包比 electron ...
  • EDP是一套集組織架構,許可權框架【功能許可權,操作許可權,數據訪問許可權,WebApi許可權】,自動化日誌,動態Interface,WebApi管理等基礎功能於一體的,基於.net的企業應用開發框架。通過友好的編碼方式實現數據行、列許可權的管控。 ...
  • .Net8.0 Blazor Hybird 桌面端 (WPF/Winform) 實測可以完整運行在 win7sp1/win10/win11. 如果用其他工具打包,還可以運行在mac/linux下, 傳送門BlazorHybrid 發佈為無依賴包方式 安裝 WebView2Runtime 1.57 M ...