本文实例为大家分享了convinientbanner顶部广告轮播控件的具体代码,供大家参考,具体内容如下
gradle中添加
compile 'com.bigkoo:convenientbanner:2.0.5'
布局
activity中
public class MainActivity extends AppCompatActivity { private String[] images = {"http://img2.imgtn.bdimg.com/it/u=3093785514,1341050958&fm=21&gp=0.jpg", "http://img2.3lian.com/2014/f2/37/d/40.jpg", "http://d.3987.com/sqmy_131219/001.jpg", "http://img2.3lian.com/2014/f2/37/d/39.jpg", "http://www.8kmm.com/UploadFiles/2012/8/201208140920132659.jpg", "http://f.hiphotos.baidu.com/image/h%3D200/sign=1478eb74d5a20cf45990f9df460b4b0c/d058ccbf6c81800a5422e5fdb43533fa838b4779.jpg", "http://f.hiphotos.baidu.com/image/pic/item/09fa513d269759ee50f1971ab6fb43166c22dfba.jpg" }; //轮播下面的小点 private int[] indicator={R.drawable.icon_selected,R.drawable.icon_unselected}; private ConvenientBanner convenientBanner; //图片加载地址的集合 private Listbean; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); convenientBanner = (ConvenientBanner) findViewById(R.id.convenientBanner); bean= Arrays.asList(images); convenientBanner.setPointViewVisible(true) //设置小点 .setPageIndicator(indicator); //允许手动轮播 convenientBanner.setManualPageable(true); //设置自动轮播的时间 convenientBanner.startTurning(3000); //设置点击事件 //泛型为具体实现类ImageLoaderHolder convenientBanner.setPages(new CBViewHolderCreator () { @Override public NetImageLoadHolder createHolder() { return new NetImageLoadHolder(); } },bean); //设置每个pager的点击事件 convenientBanner.setonItemClickListener(new onItemClickListener() { @Override public void onItemClick(int position) { Toast.makeText(MainActivity.this, "点击了"+convenientBanner.getCurrentItem(), Toast.LENGTH_SHORT).show(); } }); }
public class NetImageLoadHolder implements Holder{ private ImageView image_lv; //可以是一个布局也可以是一个Imageview @Override public ImageView createView(Context context) { image_lv=new ImageView(context); image_lv.setScaleType(ImageView.ScaleType.FIT_XY); return image_lv; } @Override public void UpdateUI(Context context, int position, String data) { Glide.with(context).load(data).placeholder(R.mipmap.ic_launcher).into(image_lv); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。