android 轮播图

最近做项目,自己封装了一个图片轮播的组件,主要的思想就采用ViewPager和ScrollGater实现,图片

加载用的Imageloader,也可以换其他的,比如Glide.具体封装的组件件源码,这里只说下用法,首先上

布局文件。


android 轮播图_第1张图片
图片名称


    

        
        
    



初始化ShufflingView,设置des可见,轮播的指示器在底部。设置点击事件监听。

mShufflingView = (ShufflingView) findViewById(R.id.shuffling_view);
        mShufflingView.setContentDesVisibility(View.VISIBLE);
        mShufflingView.setDotGravity(Gravity.BOTTOM);
        mShufflingView.setOnItemClickListener(mOnShufflingItemClickListener);
        bannerList = new ArrayList();
        loadShuffingViewData();

设置shufflingView 的beans接收的是一个arraylist对象。


ShufflingItemBean shufflingItemBean=new ShufflingItemBean();
        shufflingItemBean.setImg

("http://img3.imgtn.bdimg.com/it/u=4227020988,3565099621&fm=21&gp=0.jpg");
        shufflingItemBean.setUrl("www.baidu.com");//点击跳转到webview
        bannerList.add(shufflingItemBean);
        bannerList.add(shufflingItemBean);
        bannerList.add(shufflingItemBean);
        mShufflingView.updateDatas(bannerList);

shufflingView 的监听,具体的跳转和类型,根据需求组件设置。

private  void actionFromType(Context context, ShufflingItemBean item) {
        if (item.getType().equals("-1")) {
            return;
        } else if (item.getType().equals("1")) {// 交易贴

        } else if (item.getType().equals("2")) {// 外部链接

        } else if (item.getType().equals("3")) {// 资讯贴

        } else if (item.getType().equals("4")) {// 应援贴

        } else if (item.getType().equals("5")) {//
            //Intent intent = new Intent(context, WebViewActivity.class);


            //intent.putExtra("url",
            //item.getUrl());


            //intent.putExtra("type", 1);
            //context.startActivity(intent);
        } else {// 其他

        }

    }

代码并不难,希望通过我这个例子,一是巩固自己的学习和理解,二是希望更多的人更好的学习,我会

再接再厉,写更多的博文。

源码下载

我的微信公众号:行走的那些事,欢迎大家扫一扫。


android 轮播图_第2张图片
行走的那些事

你可能感兴趣的:(android 轮播图)