Android开源项目LoopViewPage使用

来源:互联网 发布:mac os 10.12.6怎么样 编辑:程序博客网 时间:2024/05/23 01:21

使用步骤

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

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

这里写图片描述

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:表示从服务器获取轮播图文字的集合