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

Android自動(dòng)播放Banner圖片輪播效果

 更新時(shí)間:2020年07月23日 09:24:05   作者:a940659387  
這篇文章主要介紹了Android自動(dòng)播放Banner圖片輪播效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自動(dòng)播放Banner圖片輪播的具體代碼,供大家參考,具體內(nèi)容如下

先看一下效果圖

支持本地圖片以及網(wǎng)絡(luò)圖片or本地網(wǎng)絡(luò)混合。

使用方式:

<com.jalen.autobanner.BannerView
 android:id="@+id/banner"
 android:layout_width="match_parent"
 android:layout_height="230dip">
</com.jalen.autobanner.BannerView>

核心代碼:

 int length = mList.size();
 View view = LayoutInflater.from(mContext).inflate(R.layout.banner_view,this,true);
 LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_points);
 vp= (ViewPager) view.findViewById(R.id.vp);
 ll.removeAllViews();
 LinearLayout.LayoutParams ll_parmas = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
 ll_parmas.leftMargin=5;
 ll_parmas.rightMargin=5;
 for(int i=0;i<length;i++){
 ImageView img = new ImageView(mContext);
 img.setLayoutParams(ll_parmas);
 if(i==0){
 img.setImageResource(R.mipmap.dot_focus);
 }else{
 img.setImageResource(R.mipmap.dot_blur);
 }
 ll.addView(img);
 mImgs.add(img);

 final ImageView imgforview = new ImageView(mContext);
 imgforview.setOnClickListener(this);
 imgforview.setScaleType(ImageView.ScaleType.FIT_XY);
 if(mList.get(i).getType()==0){//本地圖片
 imgforview.setImageResource(mList.get(i).getDrawableforint());

 }else{//網(wǎng)絡(luò)
 Glide.with(mContext).load(mList.get(i).getDrawableforurl()).diskCacheStrategy(DiskCacheStrategy.ALL).into(imgforview);
// Glide.with(mContext).load(mList.get(i).getDrawableforurl()).listener(new RequestListener<String, GlideDrawable>() {
//  @Override
//  public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
//  Log.d("yu","Faile:"+e.toString());
//  return false;
//  }
//
//  @Override
//  public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
//  imgforview.setImageDrawable(resource);
//  return false;
//  }
// }).into(imgforview);
// Log.d("yu","url: "+mList.get(i).getDrawableforurl());
 }
 mViews.add(imgforview);
 }

 vp.setAdapter(new MyAdapter());
 vp.addOnPageChangeListener(onPageChange);

自動(dòng)輪播利用的是handler的postdelay方法。

private Runnable task = new Runnable() {
 @Override
 public void run() {
 if(isAuto){
 currentItem = currentItem%(mViews.size());
// Log.d("yu","runalbe "+currentItem);
 if(currentItem==0){
  vp.setCurrentItem(currentItem,false);
 }else{
  vp.setCurrentItem(currentItem);
 }
 currentItem++;
 mHandle.postDelayed(task,delaytime);
 }else{
 mHandle.postDelayed(task,delaytime);
 }
 }
 };

利用isAuto判斷是否正在自動(dòng)輪播 如果為false 不自動(dòng)切換item。isAuto賦值操作位于OnPageChangeListener的onPageScrollStateChanged方法中:

 public void onPageScrollStateChanged(int state) {

 switch (state){
 case ViewPager.SCROLL_STATE_IDLE://用戶什么都沒有操作
  isAuto=true;
  currentItem = vp.getCurrentItem();
//  Log.d("yu","IDLE"+currentItem);
//  if(vp.getCurrentItem()==mViews.size()){
//  vp.setCurrentItem(0,false);
//  }
  break;
 case ViewPager.SCROLL_STATE_DRAGGING://正在滑動(dòng)
  isAuto =false;
  break;
 case ViewPager.SCROLL_STATE_SETTLING://滑動(dòng)結(jié)束
  isAuto=true;
  break;

 }
 }

當(dāng)狀態(tài)為SCROLL_STATE_DRAGGING時(shí) 說明用戶正在操作 ,看下源碼中的解釋:

 /**
 * Indicates that the pager is in an idle, settled state. The current page
 * is fully in view and no animation is in progress.
 */
 public static final int SCROLL_STATE_IDLE = 0;

 /**
 * Indicates that the pager is currently being dragged by the user.
 */
 public static final int SCROLL_STATE_DRAGGING = 1;

 /**
 * Indicates that the pager is in the process of settling to a final position.
 */
 public static final int SCROLL_STATE_SETTLING = 2;

大致意思呢就是 0代碼沒有任何操作。1頁面正在被用戶拖動(dòng)。2代表成功切換至下一頁面。

源碼地址:https://github.com/yudehai0204/autoBanner

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android播放視頻的三種方式

    Android播放視頻的三種方式

    這篇文章主要為大家詳細(xì)介紹了Android播放視頻的三種方式,使用其自帶的播放器、VideoView、MediaPlayer類和SurfaceView來實(shí)現(xiàn),感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android Gradle Plug 4.1.0 升級(jí)后gradle獲取manifest位置失敗問題解決

    Android Gradle Plug 4.1.0 升級(jí)后gradle獲取manifest位置失敗問題解決

    這篇文章主要介紹了Android Gradle Plug 4.1.0 升級(jí)后gradle獲取manifest位置失敗問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • android RecyclerView添加footerview詳解

    android RecyclerView添加footerview詳解

    大家好,本篇文章主要講的是android RecyclerView添加footerview詳解,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-01-01
  • 用Kotlin打造一個(gè)Router的示例代碼

    用Kotlin打造一個(gè)Router的示例代碼

    本篇文章主要介紹了用Kotlin打造一個(gè)Router的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-05-05
  • Android編程之圖片顏色處理方法

    Android編程之圖片顏色處理方法

    這篇文章主要介紹了Android編程之圖片顏色處理方法,涉及Android針對(duì)圖片的顏色值、飽和度、透明度等處理技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Android中butterknife的使用與自動(dòng)化查找組件插件詳解

    Android中butterknife的使用與自動(dòng)化查找組件插件詳解

    這篇文章主要給大家介紹了關(guān)于Android中butterknife的使用與自動(dòng)化查找組件插件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • Android開發(fā)之關(guān)于項(xiàng)目

    Android開發(fā)之關(guān)于項(xiàng)目

    本文是此系列文章的第二篇,給大家介紹的是項(xiàng)目相關(guān)的內(nèi)容,非常的細(xì)致全面,有需要的小伙伴可以參考下
    2016-02-02
  • kotlin?中的構(gòu)造函數(shù)的作用

    kotlin?中的構(gòu)造函數(shù)的作用

    這篇文章主要介紹了Kotlin中的構(gòu)造函數(shù),包括主構(gòu)造函數(shù)和輔助構(gòu)造函數(shù)的作用,主構(gòu)造函數(shù)用于初始化類的屬性,而輔助構(gòu)造函數(shù)通過委托給主構(gòu)造函數(shù)來實(shí)現(xiàn)更靈活的初始化方式,感興趣的朋友一起看看吧
    2025-03-03
  • Android判斷app是否在后臺(tái)運(yùn)行

    Android判斷app是否在后臺(tái)運(yùn)行

    這篇文章主要為大家介紹了Android判斷app是否在后臺(tái)運(yùn)行的實(shí)現(xiàn)流程及代碼實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-11-11
  • 利用Jetpack Compose實(shí)現(xiàn)主題切換功能

    利用Jetpack Compose實(shí)現(xiàn)主題切換功能

    這篇文章主要介紹了如何利用Android中的Jetpack Compose實(shí)現(xiàn)主題切換功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)有一定幫助,需要的可以參考一下
    2022-01-01

最新評(píng)論

晋城| 图们市| 元谋县| 崇仁县| 墨竹工卡县| 吉木乃县| 吉林市| 晴隆县| 共和县| 陇西县| 马边| 叶城县| 光泽县| 团风县| 武夷山市| 武平县| 贡山| 疏勒县| 枣庄市| 当涂县| 青川县| 德阳市| 泰顺县| 南康市| 辽阳市| 比如县| 延津县| 怀仁县| 临邑县| 高阳县| 孝感市| 平乡县| 洪江市| 平定县| 新密市| 克拉玛依市| 乌兰浩特市| 富锦市| 靖西县| 缙云县| 宜州市|