自定義封裝 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
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...