ViewPager中代码动态的添加小圆点作为指示器indicator,以及实现无限轮播

博客介绍了在Android中如何在ViewPager中动态添加小圆点作为指示器,并实现无限轮播。通过使用两个不同颜色的点图片,结合onPageSelected()方法更新选中状态,实现轮播效果。同时指出这种方法适用于头布局,且在onPageScrolled()中更新位置可观察到动画效果。
摘要由CSDN通过智能技术生成

1.首先我们需要一个相对布局装一个线性布局的容器和一个白色的小点作为选中的标识,用灰点表示未选中的情况。

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="230dp"/>

    <RelativeLayout
        android:layout_gravity="bottom|center_horizontal"
        android:layout_marginBottom="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/ll_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

        </LinearLayout>
        <View
            android:id="@+id/v_guide_white_point"
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:background="@drawable/shape_point_white"/>

    </RelativeLayout>

两种颜色的小点的xml文件如下,使用自定义shape。
shape_point_gray.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid android:color="@android:color/darker_gray"/>

</shape>

shape_point_white.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/andr
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值