<com.youth.banner.Banner android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="150dp" />
添加依赖
compile 'com.youth.banner:banner:1.4.9'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
_________________________
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import com.youth.banner.Banner; import java.util.ArrayList; import java.util.Arrays; public class MainActivity extends AppCompatActivity { private Banner banner; String[] urls = {"https://img-my.csdn.net/uploads/201407/26/1406383265_8550.jpg", "https://lh4.googleusercontent.com/--dq8niRp7W4/URquVgmXvgI/AAAAAAAAAbs/-gnuLQfNnBA/s160-c/A%252520Song%252520of%252520Ice%252520and%252520Fire.jpg", "https://lh5.googleusercontent.com/-7qZeDtRKFKc/URquWZT1gOI/AAAAAAAAAbs/hqWgteyNXsg/s160-c/Another%252520Rockaway%252520Sunset.jpg", "https://lh3.googleusercontent.com/--L0Km39l5J8/URquXHGcdNI/AAAAAAAAAbs/3ZrSJNrSomQ/s160-c/Antelope%252520Butte.jpg", "https://lh6.googleusercontent.com/-8HO-4vIFnlw/URquZnsFgtI/AAAAAAAAAbs/WT8jViTF7vw/s160-c/Antelope%252520Hallway.jpg", "https://lh4.googleusercontent.com/-WIuWgVcU3Qw/URqubRVcj4I/AAAAAAAAAbs/YvbwgGjwdIQ/s160-c/Antelope%252520Walls.jpg"}; ArrayList<String> list = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); banner = (Banner) findViewById(R.id.banner); //图片加载器 banner.setImageLoader(new BannerImageLoader()); // 设置图片集合 banner.setImages(Arrays.asList(urls)); //启动轮播 banner.start(); } }
________________________
import com.youth.banner.loader.ImageLoader; /** * Created by Administrator on 2017/2/14. */ /** * 图片加载器类; 专门让你重写显示图片的方法displayImage, * 具体怎么重写呢, 你想怎么重写,你就怎么重写; */ public class BannerImageLoader extends ImageLoader { /** * @param context * @param obj 这个传过来的的是图片接口 * @param imageView */ @Override public void displayImage(Context context, Object obj, ImageView imageView) { com.nostra13.universalimageloader.core.ImageLoader imageLoaderInstance = com.nostra13.universalimageloader.core.ImageLoader.getInstance(); imageLoaderInstance.displayImage((String) obj, imageView); } }