第一:权限配置
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
第二:依赖包
compile 'com.squareup.okio:okio:1.5.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.youth.banner:banner:1.4.9'
//compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.github.bumptech.glide:glide:3.7.0'
第三加布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="150dp">
<com.youth.banner.Banner
android:id="@+id/mybanner"
android:layout_width="match_parent"
android:layout_height="150dp"></com.youth.banner.Banner>
</LinearLayout>
MainActivity:
public class MainActivity extends AppCompatActivity { String mpath="http://result.eolinker.com/umIPmfS6c83237d9c70c7c9510c9b0f97171a308d13b611?uri=homepage"; private Banner mbanner; List mlist=new ArrayList(); List<HomeBean.DataBean.Ad1Bean> ad1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mbanner= (Banner) findViewById(R.id.mybanner); getData(mpath); } private void getData(String mpath) { OkHttp3Utils.getInstance().doGet(mpath, new GsonObjectCallback<HomeBean>() { @Override public void onUi(HomeBean homeBean) { for(int i=0; i<homeBean.getData().getAd1().size();i++){ String ad1s = homeBean.getData().getAd1().get(i).getImage(); mlist.add(ad1s); } //设置图片加载器 mbanner.setImageLoader(new GlideImageLoader()); mbanner.setImages(mlist); mbanner.start(); } @Override public void onFailed(Call call, IOException e) { } }); } }GlideImageLoader 类
public class GlideImageLoader extends ImageLoader{ @Override public void displayImage(Context context, Object path, ImageView imageView) { Glide.with(context).load(path).into(imageView); } }