继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

最火Android开源项目LoopViewPage使用

UYOU
关注TA
已关注
手记 295
粉丝 86
获赞 458

开源地址: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 LoopViewPager loopViewPager;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_simple_demo2);
    loopViewPager = (LoopViewPager) findViewById(R.id.lvp_pager);
    loopViewPager.setImgData(DataFactory.imgListString());
    loopViewPager.setTitleData(DataFactory.titleListString());
    loopViewPager.start();
}private List<String> imgListString() {
    List<String> imageData = new ArrayList<>();
    imageData.add("http://d.hiphotos.baidu.com/image/h%3D200/sign=72b32dc4b719ebc4df787199b227cf79/58ee3d6d55fbb2fb48944ab34b4a20a44723dcd7.jpg");
    imageData.add("http://pic.4j4j.cn/upload/pic/20130815/31e652fe2d.jpg");
    imageData.add("http://pic.4j4j.cn/upload/pic/20130815/5e604404fe.jpg");
    imageData.add("http://pic.4j4j.cn/upload/pic/20130909/681ebf9d64.jpg");
    imageData.add("http://d.hiphotos.baidu.com/image/pic/item/54fbb2fb43166d22dc28839a442309f79052d265.jpg");    return imageData;
}private List<String> titleListString() {
    List<String> titleData = new ArrayList<>();
    titleData.add("1、在这里等着你");
    titleData.add("2、在你身边");
    titleData.add("3、打电话给你就是想说声“嗨”");
    titleData.add("4、不介意你对我大喊大叫");
    titleData.add("5、期待你总是尽全力");    return titleData;
}

细节注意:

imgListString:表示从服务器获取轮播图图片的url地址集合

titleListString:表示从服务器获取轮播图文字的集合

获取服务器数据推荐使用github最火开源项目RetrofitUtils.



作者:马伟奇
链接:https://www.jianshu.com/p/f847325e8a28


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP