Android轮播图Banner使用方法

//轮播图导包

compile 'com.youth.banner:banner:1.4.9'

//布局中使用

 



 

 

 

//Activity中使用

 

import android.content.Context;
        import android.os.Bundle;
        import android.support.v7.app.AppCompatActivity;
        import android.widget.ImageView;

        import com.bumptech.glide.Glide;
        import com.youth.banner.Banner;
        import com.youth.banner.BannerConfig;
        import com.youth.banner.loader.ImageLoader;

        import java.util.ArrayList;
        import java.util.List;

public class MainActivity extends AppCompatActivity {

    private Banner banner;
    String arr[] = {"http://img06.tooopen.com/images/20170321/tooopen_sl_202648839562.jpg",
            "http://img06.tooopen.com/images/20170511/tooopen_sl_209123759718.jpg",
            "http://img06.tooopen.com/images/20170514/tooopen_sl_209849059366.jpg",
            "http://img06.tooopen.com/images/20170514/tooopen_sl_209992249686.jpg",
            "http://img07.tooopen.com/images/20170215/tooopen_sl_198728099565.jpg"};
    private List list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        banner = (Banner) findViewById(R.id.banner);
        list = new ArrayList<>();
        for (String s:arr){
            list.add(s);
        }
	//加载本地图片方法,和上面加载网络图片,自己选择
 
ArrayList list = new ArrayList<>();  list.add(R.mipmap.test03);  list.add(R.mipmap.fest04);  list.add(R.mipmap.test05);  list.add(R.mipmap.test06);
	viewpager.setImageLoader(new GlideImageLoader());//加载图片
	viewpager.setImages(list);//设置图片的集合
	viewpager.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);//设置圆点的样式
	viewpager.setDelayTime(3500);//轮播间隔时间
	viewpager.start();
    }
 
public class GlideImageLoader extends ImageLoader {  @Override   public void displayImage(Context context, Object path, ImageView imageView) { Glide.with(context).load(path).into(imageView);   }  }

}

你可能感兴趣的:(Android)