美文网首页Android干货Android所有文章都配视频讲解我的Andorid 收藏
开源中国系列三:一行代码实现资讯页面轮播图

开源中国系列三:一行代码实现资讯页面轮播图

作者: 小怪兽打葫芦娃 | 来源:发表于2017-02-24 19:59 被阅读253次

    自定义控件

    联网

    工具

    数据库

    源码分析相关面试题

    Activity相关面试题

    Service相关面试题

    与XMPP相关面试题

    与性能优化相关面试题

    与登录相关面试题

    与开发相关面试题

    与人事相关面试题

    开源地址:https://github.com/open-android/LoopViewPager

    使用步骤

    1. 在project的build.gradle添加如下代码(如下图)

    allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }
    
    jitpack.png

    2. 在Module的build.gradle添加依赖

    compile 'com.github.open-android:LoopViewPager:1.0.0'
    

    3. 复制如下代码到xml

    <com.itheima.loopviewpager.LoopViewPager
        android:id="@+id/lvp_pager"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        app:animStyle="accordion"
        app:animTime="1000"
        app:loopTime="3000">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="#55000000"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="10dp">
            //表示轮播图的文字
            <com.itheima.loopviewpager.LoopTitleView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:maxLines="1"
                android:textColor="#FF0000"
                android:textSize="16sp" />
            //表示轮播图的点
            <com.itheima.loopviewpager.LoopDotsView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                app:dotShape="oval"
                app:dotSize="10dp" />
    
        </LinearLayout>
    
    </com.itheima.loopviewpager.LoopViewPager>
    

    4. 复制如下代码到Activity

      private void initBanneer() {
            Request request = ItheimaHttp.newGetRequest("action/apiv2/banner?   catalog=1");//apiUrl格式:"xxx/xxxxx"
          Call call = ItheimaHttp.send(request, new HttpResponseListener<BannerBean>() {
            @Override
            public void onResponse(BannerBean bean, Headers headers) {
    
    
                List<BannerBean.ResultEntity.ItemsEntity> itemDatas = bean.getItemDatas();
    
                for (int i = 0; i < itemDatas.size(); i++) {
                    textLists.add(itemDatas.get(i).name);
                    imageLists.add(itemDatas.get(i).img);
                }
                mLoopViewPager.setImgData(imageLists);
                mLoopViewPager.setTitleData(textLists);
                mLoopViewPager.start();
            }
    
        });
    }
    

    欢迎关注微信公众号

    微信公众号名称:Android干货程序员

    相关文章

      网友评论

      • JackChen1024:马老师,有开源中国的代码和接口文档吗吗,跟视频配套的,能分享一下吗?谢谢。815712739@qq.com

      本文标题:开源中国系列三:一行代码实现资讯页面轮播图

      本文链接:https://www.haomeiwen.com/subject/tcowwttx.html