前言:Circle适用于应用新功能的展示页和商品的多张图片的展示功能。

    1.定义布局文件:SampleCirclesDefault中添加了一个布局:simple_circles。

     布局中定义一个LinearLayout垂直布局,添加一个viewpager和com.viewpagerindicatorCirclePageIndictor必须是完全限定名。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >     <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />     <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/indicator"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip" /> </LinearLayout>

 2.代码中调用布局

setContentView(R.layout.simple_circles);
        //定义一个iewpager的adaper
        mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
        //定义个Pager,即布局中定义的那个pagerview
        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);
        //定义一个指示变量,即布局中定义的那个
        CirclePageIndicator indicator = (CirclePageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(mPager);

完成以上的代码就可以使用了。这里面需要一个ViewPagerAdatper

 3.上面是简单的使用,并没有修改指示的颜色和大小等属性,现在通过他提供的方法我们来定义自己的指示。一下是CirclePageIndicator提供的属性。

<declare-styleable name="CirclePageIndicator">

        <!-- 指示标识是否居中 -->
        <attr name="centered" />
        <!-- 当前选择指示的颜色 -->
        <attr name="fillColor" format="color" />
        <!-- 当前未被选择指示的颜色 -->
        <attr name="pageColor" format="color" />
        <!-- 指示的布局方式,水平还是垂直 -->
        <attr name="android:orientation" />
        <!-- 指示的大小 -->
        <attr name="radius" format="dimension" />
        <!-- 指示是否快速滑动 -->
        <attr name="snap" format="boolean" />
        <!-- 描边的颜色 -->
        <attr name="strokeColor" format="color" />
        <!-- 描边的宽度 -->
        <attr name="strokeWidth" />
        <!-- 指示整体的背景色 -->
        <attr name="android:background" />
    </declare-styleable>

    4.改变属性:有三种方法

      1.在布局中更改:其中的xmlns:app是后面那个http路径的简称,方便使用,这个结尾用的是res-auto,没见过,估计是自动查找,正常的写法是这样的

        xmlns:app1="http://schemas.android.com/apk/res/com.viewpagerindicator.sample",即res/项目完全限定名。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">     <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />
    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/indicator"
        android:padding="10dip"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="#FFCCCCCC"
        app:radius="10dp"
        app:fillColor="#FF888888"
        app:pageColor="#88FF0000"
        app:strokeColor="#FF000000"
        app:strokeWidth="2dp"
        />
</LinearLayout>

 2.代码里修改:

CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
        indicator.setViewPager(mPager);         final float density = getResources().getDisplayMetrics().density;
        indicator.setBackgroundColor(0xFFCCCCCC);
        indicator.setRadius(10 * density);
        indicator.setPageColor(0x880000FF);
        indicator.setFillColor(0xFF888888);
        indicator.setStrokeColor(0xFF000000);
        indicator.setStrokeWidth(2 * density);

3.主题修改:

<activity
            android:name=".SampleCirclesStyledTheme"
            android:label="Circles/Styled (via theme)"
            android:theme="@style/CustomCirclePageIndicator" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />                 <category android:name="com.jakewharton.android.viewpagerindicator.sample.SAMPLE" />
            </intent-filter>
        </activity>
 CustomCirclePageIndicator主题如下
<style name="CustomCirclePageIndicator" parent="@android:style/Theme.Light">
        <item name="fillColor">#FF888888</item>
        <item name="strokeColor">#FF000000</item>
        <item name="strokeWidth">2dp</item>
        <item name="radius">10dp</item>
        <item name="centered">true</item>
    </style>
4.为viewpager设置监听:
mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                Toast.makeText(SampleCirclesWithListener.this, "Changed to page " + position, Toast.LENGTH_SHORT).show();
            }             @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }             @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

Android-ViewPagerIndicator框架使用——CirclePageIndicator的更多相关文章

  1. Android开源框架ViewPagerIndicator的基本使用

    转载本博客请注明出处:点击打开链接    http://blog.csdn.net/qq_32059827/article/details/52495647 很多新闻资讯类的app都有一些共性,那就是 ...

  2. Android百大框架排行榜

    Android百大框架排行榜 15类Android通用流行框架 - 流风,飘然的风 - 博客园https://www.cnblogs.com/zdz8207/p/android-opensource- ...

  3. 2017年Android百大框架排行榜

    框架:提供一定能力的小段程序 >随意转载,标注作者"金诚"即可 >本文已授权微信公众号:鸿洋(hongyangAndroid)原创首发. >本文已经开源到Gith ...

  4. android 优秀框架整理

    程序员界有个神奇的网站,那就是github,这个网站集合了一大批优秀的开源框架,极大地节省了开发者开发的时间,在这里我进行了一下整理,这样可以使我们在使用到时快速的查找到,希望对大家有所帮助! 1. ...

  5. 2017年Android百大框架排行榜(转)

    一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由.网络层.UI层.通信层或其他单一功能的框架 混合开发框架:提供开发hybrid app.h5与webview结合能力.web app能力的框架 ...

  6. Android开源框架ViewPageIndicator和ViewPager实现Tab导航

    前言: 关于使用ViewPageIndicator和ViewPager实现Tab导航,在开发社区里已经有一堆的博客对其进行了介绍,假设我还在这里写怎样去实现.那简直就是老生常谈,毫无新奇感,并且.我也 ...

  7. Android 开源框架Universal-Image-Loader学习

    Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用 Android 开源框架Universal-Image-Loader完全解析(二)--- 图片 ...

  8. Android 数据库框架OrmLite的使用(一)

    在这里记录下最基本的用法,官网上可了解相关的介绍. 1.下载OrmLite jar 在下载android的:ormlite-android-4.48.jar和ormlite-core-4.48.jar ...

  9. Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/39057201),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...

随机推荐

  1. bzoj 4753 最佳团体 —— 01分数规划+树形背包

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4753 注意赋初值为 -inf: eps 设为 1e-3 会 WA ... 代码如下: #in ...

  2. [九省联考2018]一双木棋chess——搜索+哈希

    题目:bzoj5248 https://www.lydsy.com/JudgeOnline/problem.php?id=5248 洛谷P4363 https://www.luogu.org/prob ...

  3. UI:数据的解析

    在懒加载的时候要注意事项: 必须使用 self.XX 的样式去开辟空间,不能使用 _XX 的格式去开辟,因为前者是内部的 set 方法,而后者并不走内部的 set 方法. json 文件的创建  xm ...

  4. 使用oracle的保留字作为字段名称并进行操作的方法

    项目中调取业主的数据库时发现,其中一个表的一个字段名为:update,所以当我用数据库查询语句进行查询的时候总会出错.从网上查询之后发现原来很简单,只要把update加上双引号就好了,例如: sele ...

  5. 【算法小总结】LCS问题&&HDU1243

    LCS问题,又称最长公共子序列问题,是DP中较简单的一种,今天我们就来简单讲解一下. 设s1:AEGLEGLLELGEL 设s2:LREGELGEGLEG 求两个字符串的最大公共子序列长度 输出:8 ...

  6. spoj 371 Boxes【最小费用最大流】

    对于ai==0连接(i,t,1,0),对于ai>1(s,i,ai-1,0),然后对以相邻的两个点(i,j)连接(i,j,inf,1),注意这里是一个环的形式,所以1和n+1相连 #include ...

  7. Android项目通过Android Debug Database实时查看本地Sqlite数据库内容

    前几天写Android项目时,想和Sqlyog那样图形化查看数据库中的文件,由于Android自带小型的Sqlite轻量级数据库,在查找方法时发现了一个特别简单适用的方法,纪录一下. 在android ...

  8. PHP arrray_filter(), array_map()区别与应用

    array_filter()用回调函数过滤数组中的元素.依次将数组中的元素传递给回调函数,如果回调函数返回true,则被过滤的元素作为返回数组的元素,并最终一起返回.数组的键名保持不变.array_m ...

  9. shiro之SimpleAccountRealm

    我使用的是maven构建的工程,junit测试 Shiro认证过程 创建SecurityManager--->主体提交认证--->SecurityManager认证--->Authe ...

  10. 数论(GCD) HDOJ 4320 Arcane Numbers 1

    题目传送门 题意:有一个A进制的有限小数,问能否转换成B进制的有限小数 分析:0.123在A进制下表示成:1/A + 2/(A^2) + 3 / (A^3),转换成B进制就是不断的乘B直到为0,即(1 ...