最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android banner詳解用法案例

 更新時間:2021年11月03日 11:58:53   作者:小旺不正經(jīng)  
android-banner實現(xiàn)了一般banner循環(huán)輪播的效果,一頁只顯示一張圖片,也可以一頁顯示一張圖和相鄰兩個圖片的一部分,此項目僅僅是banner展示圖片,沒有多余的諸如指示器、頁面切換動畫等效果代碼,詳見效果圖和案例代碼

Android----banner使用詳解

在這里插入圖片描述

昨天10.31 ,斗破蒼穹的三年之約終于出來了,自己也等了很久很久,敬師長,敬家人,敬朋友,敬每一個前行路上正在奮戰(zhàn)的自己,星光不問趕路人,時間不負有心人。

效果圖:

在這里插入圖片描述

添加依賴

  implementation 'com.youth.banner:banner:2.1.0'

添加權(quán)限到你的 AndroidManifest.xml

<!-- if you want to load images from the internet -->
<uses-permission android:name="android.permission.INTERNET" /> 

布局文件

<com.youth.banner.Banner
        android:id="@+id/banner"
        android:layout_width="0dp"
        android:layout_height="250dp"
        android:layout_margin="10dp"
        app:banner_radius="20dp"    // 圓角
        android:clickable="true"   //  是否可點擊
        app:banner_indicator_selected_color="#95F2EC"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.157"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

邏輯代碼

package com.hnucm.xiaotang;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnBannerListener;

import org.json.JSONArray;
import org.json.JSONException;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;


public class ShouYeFragment extends Fragment implements OnBannerListener {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_shou_ye, container, false);
        Banner banner =inflate.findViewById(R.id.banner);
        List<String> imgList = new ArrayList<>();

        x.Ext.init(getActivity().getApplication());
        x.Ext.setDebug(BuildConfig.DEBUG);  // 是否輸出debug日志, 開啟debug會影響性能.
        x.view().inject(getActivity());  //沒有用到view注解可以先不用

        imgList.add("https://cdn.jsdelivr.net/gh/Yqifei/Blog-Image@master/20211026/image.6719h9mvs700.png");
        imgList.add("https://cdn.jsdelivr.net/gh/Yqifei/Blog-Image@master/20211031/800-(11).2txrpbqztva0.jpg");
        imgList.add("https://cdn.jsdelivr.net/gh/Yqifei/Blog-Image@master/20211031/800-(5).5s6zwxy19v40.jpg");
        imgList.add("https://cdn.jsdelivr.net/gh/Yqifei/Blog-Image@master/20211031/800-(10).24p8puxcmqbk.jpg");
        imgList.add("https://cdn.jsdelivr.net/gh/Yqifei/Blog-Image@master/20211031/800-(14).pizaxijh534.jpg");

        RequestParams params = new RequestParams("https://www.fastmock.site/mock/08392ee207964eb010bf22b157103494/androidJavaEE/banner");
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                try {
                    JSONArray jsonArray = new JSONArray(result);
                    for (int i=0;i<jsonArray.length();i++){
                        imgList.add((String)jsonArray.get(i));
                    }
                    banner.setDatas(imgList);    //  動態(tài)更新banner數(shù)據(jù)
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });


        banner.setAdapter(new BannerImageAdapter<String>(imgList) {

            @Override
            public void onBindView(BannerImageHolder holder, String data, int position, int size) {
                System.out.println("hello TEST");
                Glide.with(holder.itemView)
                        .load(data)
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                        .into(holder.imageView);
            }

        }).setIndicator(new 				                      CircleIndicator(getContext())).setLoopTime(1000).setOnBannerListener(this);
        //  設(shè)置圓形指示點,設(shè)置循環(huán)時間,設(shè)置監(jiān)聽器
        return inflate;
    }

    @Override
    public void OnBannerClick(Object data, int position) {   //  監(jiān)聽每一個圖片的點擊事件
        Log.i("tag", "你點了第"+position+"張輪播圖");
    }
}

常見的一些屬性設(shè)置

方法

更多方法以實際使用為準,下面不一定全部列出了

方法名 返回類型 描述
getAdapter() extends BannerAdapter 獲取你設(shè)置的BannerAdapter
getViewPager2() ViewPager2 獲取ViewPager2
getIndicator() Indicator 獲取你設(shè)置的指示器(沒有設(shè)置直接獲取會拋異常哦)
getIndicatorConfig() IndicatorConfig 獲取你設(shè)置的指示器配置信息(沒有設(shè)置直接獲取會拋異常哦)
getRealCount() int 返回banner真實總數(shù)
setUserInputEnabled(boolean) this 禁止手動滑動Banner;true 允許,false 禁止
setDatas(List) this 重新設(shè)置banner數(shù)據(jù)
isAutoLoop(boolean) this 是否允許自動輪播
setLoopTime(long) this 設(shè)置輪播間隔時間(默認3000毫秒)
setScrollTime(long) this 設(shè)置輪播滑動的時間(默認800毫秒)
start() this 開始輪播(主要配合生命周期使用),或者你手動暫停再次啟動
stop() this 停止輪播(主要配合生命周期使用),或者你需要手動暫停
setAdapter(T extends BannerAdapter) this 設(shè)置banner的適配器
setAdapter(T extends BannerAdapter,boolean) this 設(shè)置banner的適配器,是否支持無限循環(huán)
setOrientation(@Orientation) this 設(shè)置banner輪播方向(垂直or水平)
setOnBannerListener(this) this 設(shè)置點擊事件,下標是從0開始
addOnPageChangeListener(this) this 添加viewpager2的滑動監(jiān)聽
setPageTransformer(PageTransformer) this 設(shè)置viewpager的切換效果
addPageTransformer(PageTransformer) this 添加viewpager的切換效果(可以設(shè)置多個)
setIndicator(Indicator) this 設(shè)置banner輪播指示器(提供有base和接口,可以自定義)
setIndicator(Indicator,boolean) this 設(shè)置指示器(傳false代表不將指示器添加到banner上,配合布局文件,可以自我發(fā)揮)
setIndicatorSelectedColor(@ColorInt) this 設(shè)置指示器選中顏色
setIndicatorSelectedColorRes(@ColorRes) this 設(shè)置指示器選中顏色
setIndicatorNormalColor(@ColorInt) this 設(shè)置指示器默認顏色
setIndicatorNormalColorRes(@ColorRes) this 設(shè)置指示器默認顏色
setIndicatorGravity(@IndicatorConfig.Direction) this 設(shè)置指示器位置(左,中,右)
setIndicatorSpace(int) this 設(shè)置指示器之間的間距
setIndicatorMargins(IndicatorConfig.Margins) this 設(shè)置指示器的Margins
setIndicatorWidth(int,int) this 設(shè)置指示器選中和未選中的寬度,直接影響繪制指示器的大小
setIndicatorNormalWidth(int) this 設(shè)置指示器未選中的寬度
setIndicatorSelectedWidth(int) this 設(shè)置指示器選中的寬度
setIndicatorRadius(int) this 設(shè)置指示器圓角,不要圓角可以設(shè)置為0
setIndicatorHeight(int) this 設(shè)置指示器高度
setBannerRound(float) this 設(shè)置banner圓角(還有一種setBannerRound2方法,需要5.0以上)
setBannerGalleryEffect(int,int,float) this 畫廊效果
setBannerGalleryMZ(int,float) this 魅族效果
setStartPosition(int) this 設(shè)置開始的位置 (需要在setAdapter或者setDatas之前調(diào)用才有效哦)
setIndicatorPageChange() this 設(shè)置指示器改變監(jiān)聽 (一般是為了配合數(shù)據(jù)操作使用,看情況自己發(fā)揮)
setCurrentItem() this 設(shè)置當前位置,和原生使用效果一樣
addBannerLifecycleObserver() this 給banner添加生命周期觀察者,內(nèi)部自動管理banner的生命周期

在banner布局文件中調(diào)用,如果你自定義了indicator請做好兼容處理。 下面的屬性并不是每個指示器都用得到,所以使用時要注意!

Attributes format describe
banner_loop_time integer 輪播間隔時間,默認3000
banner_auto_loop boolean 是否自動輪播,默認true
banner_infinite_loop boolean 是否支持無限循環(huán)(即首尾直接過渡),默認true
banner_orientation enum 輪播方向:horizontal(默認) or vertical
banner_radius dimension banner圓角半徑,默認0(不繪制圓角)
banner_indicator_normal_width dimension 指示器默認的寬度,默認5dp (對RoundLinesIndicator無效)
banner_indicator_selected_width dimension 指示器選中的寬度,默認7dp
banner_indicator_normal_color color 指示器默認顏色,默認0x88ffffff
banner_indicator_selected_color color 指示器選中顏色,默認0x88000000
banner_indicator_space dimension 指示器之間的間距,默認5dp (對RoundLinesIndicator無效)
banner_indicator_gravity dimension 指示器位置,默認center
banner_indicator_margin dimension 指示器的margin,默認5dp,不能和下面的同時使用
banner_indicator_marginLeft dimension 指示器左邊的margin
banner_indicator_marginTop dimension 指示器上邊的margin
banner_indicator_marginRight dimension 指示器右邊的margin
banner_indicator_marginBottom dimension 指示器下邊的margin
banner_indicator_height dimension 指示器高度(對CircleIndicator無效)
banner_indicator_radius dimension 指示器圓角(對CircleIndicator無效)
banner_round_top_left boolean 設(shè)置要繪制的banner圓角方向(如果都不設(shè)置默認全部)
banner_round_top_right boolean 設(shè)置要繪制的banner圓角方向(如果都不設(shè)置默認全部)
banner_round_bottom_left boolean 設(shè)置要繪制的banner圓角方向(如果都不設(shè)置默認全部)
banner_round_bottom_right boolean 設(shè)置要繪制的banner圓角方向(如果都不設(shè)置默認全部)

github官網(wǎng): GitHub - youth5201314/banner: 🔥🔥🔥Banner 2.0 來了!Android廣告圖片輪播控件,內(nèi)部基于ViewPager2實現(xiàn),Indicator和UI都可以自定義。

到此這篇關(guān)于Python Django視圖響應(yīng)三函數(shù)詳解分析的文章就介紹到這了,更多相關(guān)Python Django內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android自定義PopWindow帶動畫向下彈出效果

    Android自定義PopWindow帶動畫向下彈出效果

    這篇文章主要為大家詳細介紹了Android自定義PopWindow帶動畫向下彈出效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Kotlin?掛起函數(shù)CPS轉(zhuǎn)換原理解析

    Kotlin?掛起函數(shù)CPS轉(zhuǎn)換原理解析

    這篇文章主要為大家介紹了Kotlin?掛起函數(shù)CPS轉(zhuǎn)換原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12
  • Android實現(xiàn)三角形氣泡效果方式匯總

    Android實現(xiàn)三角形氣泡效果方式匯總

    這篇文章主要介紹了Android實現(xiàn)三角形氣泡效果方式匯總,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • TextVie獲取顯示字符串的寬度之Android開發(fā)

    TextVie獲取顯示字符串的寬度之Android開發(fā)

    在項目開展過程中遇到問題要判斷textview是否需換行,要解決此問題首先判斷textview要顯示的字符串的寬度是否超過我設(shè)定的寬度,若超過則執(zhí)行換行,需要的朋友可以參考下
    2015-07-07
  • Android 中 Fragment的使用大全

    Android 中 Fragment的使用大全

    通常地 fragment做為宿主activity UI的一部分, 被作為activity整個view hierarchy的一部分被嵌入。本篇文章給大家介紹android fragment使用,需要的朋友一起看看吧
    2015-10-10
  • Android下的EXIF是什么

    Android下的EXIF是什么

    這篇文章主要為大家詳細介紹了Android下的EXIF是什么,Exif(Exchangeable Image File 可交換圖像文件)是一種圖象文件格式,它的數(shù)據(jù)存儲與JPEG格式是完全相同的,想要深入了解的朋友可以參考一下
    2016-04-04
  • Android視頻加水印之FFmpeg的簡單應(yīng)用實例

    Android視頻加水印之FFmpeg的簡單應(yīng)用實例

    最近有個需求,需要錄制視頻,能添加水印,所以下面這篇文章主要給大家介紹了關(guān)于Android視頻加水印之FFmpeg的簡單應(yīng)用的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-05-05
  • android計算pad或手機的分辨率/像素/密度/屏幕尺寸/DPI值的方法

    android計算pad或手機的分辨率/像素/密度/屏幕尺寸/DPI值的方法

    本文將介紹手機布局/界面設(shè)計/分辨率/密度相關(guān),接下來介紹android計算pad或手機的分辨率像素等等的方法,感興趣的朋友可以了解下,希望本文可以幫助你
    2013-01-01
  • Android Xutils3網(wǎng)絡(luò)請求的封裝詳解及實例代碼

    Android Xutils3網(wǎng)絡(luò)請求的封裝詳解及實例代碼

    這篇文章主要介紹了Android Xutils3網(wǎng)絡(luò)請求的封裝詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • Android實現(xiàn)拍照截取和相冊圖片截取

    Android實現(xiàn)拍照截取和相冊圖片截取

    這篇文章主要為大家詳細介紹了Android實現(xiàn)拍照截取和相冊獲取圖片截取,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12

最新評論

张家界市| 黑龙江省| 安康市| 三穗县| 永昌县| 通海县| 小金县| 淅川县| 兰西县| 宁晋县| 松阳县| 宁阳县| 武川县| 敦化市| 贵州省| 潼关县| 峡江县| 内乡县| 锡林郭勒盟| 澳门| 那坡县| 中宁县| 体育| 肇东市| 新郑市| 彭阳县| 武威市| 洪江市| 平乡县| 乌拉特后旗| 无锡市| 梧州市| 巴塘县| 宝坻区| 历史| 尉氏县| 永登县| 吉林省| 洛川县| 汕头市| 太原市|