package com.example.myapp; import android.content.Context; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.GridView; import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast; import com.bigkoo.convenientbanner.ConvenientBanner; import com.bigkoo.convenientbanner.holder.CBViewHolderCreator; import com.bigkoo.convenientbanner.holder.Holder; import com.bigkoo.convenientbanner.listener.OnItemClickListener; import com.bumptech.glide.Glide; import com.google.gson.Gson; import java.util.Arrays; import java.util.List; public class Main2Activity extends AppCompatActivity { private String[] images = { "http://img2.3lian.com/2014/f2/37/d/40.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.mipmap.b1, R.mipmap.b2}; private ConvenientBanner convenientBanner; //图片加载地址的集合 private List<String> bean; private List<User.ResultBean.DataBean> data; private GridView gvie; private ListView listvi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); //获取传递的数据 String name = getIntent().getStringExtra("name"); Gson gson = new Gson(); User user = gson.fromJson(name, User.class); data = user.getResult().getData(); gvie = (GridView) findViewById(R.id.gvie); listvi = (ListView) findViewById(R.id.listvi); My1Adapter myadpader = new My1Adapter(data, this); gvie.setAdapter(myadpader); listvi.setAdapter(myadpader); convenientBanner = (ConvenientBanner) findViewById(R.id.convenientBanner); bean = Arrays.asList(images); convenientBanner.setPointViewVisible(true) //设置小点 .setPageIndicator(indicator); //允许手动轮播 convenientBanner.setManualPageable(true); //设置自动轮播的时间 convenientBanner.startTurning(2000); //设置点击事件 //泛型为具体实现类ImageLoaderHolder convenientBanner.setPages(new CBViewHolderCreator<NetImageLoadHolder>() { @Override public NetImageLoadHolder createHolder() { return new NetImageLoadHolder(); } }, bean); //设置每个pager的点击事件 convenientBanner.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(int position) { Toast.makeText(Main2Activity.this, "点击了" + convenientBanner.getCurrentItem(), Toast.LENGTH_SHORT).show(); } }); } public class NetImageLoadHolder implements Holder<String> { 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框架 Glide.with(context).load(data).into(image_lv); } } }
轮播图+GridView+Listview
最新推荐文章于 2018-11-08 19:14:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)