1. 需要的jar包
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.youth.banner:banner:1.4.4'
2. github 地址
https://github.com/youth5201314/banner
https://github.com/bumptech/glide
3. layout.xml
<com.youth.banner.Banner
android:id="@+id/homeBanner"
android:layout_width="match_parent"
android:layout_height="100dp" />
4. Java类
public class HomeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_home, container, false);
initBanner(root);
return root;
}
private void initBanner(View root){
Banner homeBanner;
List<String> images = new ArrayList<String>();
images.add("https://www.vipcio.com/themes/mobile/images/index/slide0.jpg?v=1");
images.add("https://www.vipcio.com/themes/mobile/images/index/slide1.jpg?v=1");
homeBanner = (Banner) root.findViewById(R.id.homeBanner);
homeBanner.setImages(images);
homeBanner.setBannerStyle(BannerConfig.NUM_INDICATOR);
homeBanner.setDelayTime(3000);
homeBanner.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
Glide.with(context).load(path).into(imageView);
}
});
homeBanner.start();
}
}