Android實(shí)現(xiàn)簡單的banner輪播圖
本文實(shí)例為大家分享了Android實(shí)現(xiàn)簡單banner輪播圖的具體代碼,供大家參考,具體內(nèi)容如下
說明:想玩一個(gè)簡單的輪播圖效果 用的第三方的框架玩一下,支持設(shè)置輪播圖多種樣式
1.效果圖implementation ’com.youth.banner:banner:1.4.10’implementation 'com.github.bumptech.glide:glide:4.6.1'3.主界面
package com.example.myapplication34; import android.os.Bundle; import com.youth.banner.Banner;import com.youth.banner.BannerConfig;import com.youth.banner.Transformer; import java.util.ArrayList; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { //界面控件 private Banner mbanner; //輪播圖的數(shù)據(jù) private MyImageLoader myImageLoader; private ArrayList<Integer> photos; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Bundle bundle = getIntent().getBundleExtra('bundle');initData();initView(); } //界面初始化 private void initView() {mbanner = (Banner) findViewById(R.id.banner);//設(shè)置輪播的樣式mbanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR); //CIRCLE_INDICATOR//設(shè)置圖片加載器mbanner.setImageLoader(myImageLoader);//設(shè)置輪播的動(dòng)畫效果,里面有很多種特效,可以都看看效果。mbanner.setBannerAnimation(Transformer.ZoomOutSlide);//設(shè)置輪播間隔時(shí)間mbanner.setDelayTime(3000);//設(shè)置是否為自動(dòng)輪播,默認(rèn)是truembanner.isAutoPlay(true);//設(shè)置指示器的位置,小點(diǎn)點(diǎn),居中顯示mbanner.setIndicatorGravity(BannerConfig.CENTER);//設(shè)置圖片加載地址mbanner.setImages(photos)//開始調(diào)用的方法,啟動(dòng)輪播圖。.start(); } //數(shù)據(jù)初始化 private void initData() {myImageLoader = new MyImageLoader();//將輪播的圖片放在photos 那里photos = new ArrayList<Integer>();photos.add(R.mipmap.photo2);photos.add(R.mipmap.photo1);photos.add(R.mipmap.photo3);photos.add(R.mipmap.photo4);photos.add(R.mipmap.photo5);photos.add(R.mipmap.photo6); } }4.設(shè)置圖片源數(shù)據(jù)
package com.example.myapplication34; import android.content.Context;import android.widget.ImageView; import com.bumptech.glide.Glide;import com.youth.banner.loader.ImageLoader; public class MyImageLoader extends ImageLoader { @Override public void displayImage(Context context, Object path, ImageView imageView) {Glide.with(context.getApplicationContext()).load(path).into(imageView); }}5.布局
<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'> <com.youth.banner.Bannerandroid: android:layout_width='match_parent'android:layout_height='200dp'app:layout_constraintBottom_toBottomOf='parent'app:layout_constraintTop_toTopOf='parent' /> </LinearLayout>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. XML入門的常見問題(三)2. 關(guān)于html嵌入xml數(shù)據(jù)島如何穿過樹形結(jié)構(gòu)關(guān)系的問題3. XML 非法字符(轉(zhuǎn)義字符)4. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)5. WMLScript的語法基礎(chǔ)6. 前端html+css實(shí)現(xiàn)動(dòng)態(tài)生日快樂代碼7. 不要在HTML中濫用div8. el-input無法輸入的問題和表單驗(yàn)證失敗問題解決9. JSP取得在WEB.XML中定義的參數(shù)10. 初試WAP之wml+ASP查詢
