//联网权限
//依赖
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.xhb:xbanner:1.2.2'
//布局
<com.stx.xhb.xbanner.XBanner xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/oo" android:layout_width="match_parent" android:layout_height="200dp" app:pointsPosition="CENTER" app:AutoPlayTime="3000" app:pointsContainerBackground="#44aaaaaa" />
//代码public class Main2Activity extends AppCompatActivity implements XBanner.XBannerAdapter { ArrayList<String> bannerarr = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); XBanner mBannerNet = (XBanner) findViewById(R.id.oo); bannerarr.add("https://p1.pstatp.com/obj/573b00027992d9665a44"); bannerarr.add("https://p1.pstatp.com/obj/551f00049bcedf3213fa"); bannerarr.add("https://p3.pstatp.com/obj/383e00044b4cc3518d2d"); bannerarr.add("https://p3.pstatp.com/obj/42a30007b8ae7b956804"); mBannerNet.setData(bannerarr,null); // 设置XBanner的页面切换特效 mBannerNet.setPageTransformer(Transformer.Default); // 设置XBanner页面切换的时间,即动画时长 mBannerNet.setPageChangeDuration(2000); mBannerNet.setmAdapter(this); } //加载banner图片的适配器 @Override public void loadBanner(XBanner banner, View view, int position) { Glide.with(this).load(bannerarr.get(position)).into((ImageView) view); } }