implementation 'jp.wasabeef:glide-transformations:3.0.1' implementation 'com.xhb:xbanner:1.2.2' implementation 'com.nineoldandroids:library:2.4.0'
<com.stx.xhb.xbanner.XBanner android:id="@+id/fragment_curricula_lunbo" android:layout_width="match_parent" android:layout_height="200dp" android:layout_below="@+id/layout">
</com.stx.xhb.xbanner.XBanner>
// 初始化XBanner中展現的數據
final ArrayList<String> images = new ArrayList<>(); for (int i = 0; i <homeBanner.size() ; i++) { images.add(homeBanner.get(i).getBannerUrl()); } // 爲XBanner綁定數據
fragment_curricula_lunbo.setData(images, null); // XBanner適配數據
fragment_curricula_lunbo.setmAdapter(new XBanner.XBannerAdapter() { @Override public void loadBanner(XBanner banner, View view, int position) { Glide.with(getActivity()).load(images.get(position)).into((ImageView) view); } }); // 設置XBanner的頁面切換特效
fragment_curricula_lunbo.setPageTransformer(Transformer.Default); // 設置XBanner頁面切換的時間,即動畫時長
fragment_curricula_lunbo.setPageChangeDuration(1000);
@Override public void onResume() { super.onResume(); fragment_curricula_lunbo.startAutoPlay(); } @Override public void onStop() { super.onStop(); fragment_curricula_lunbo.stopAutoPlay(); }