Android-ViewPagerIndicator框架使用——CirclePageIndicator
前言: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的更多相关文章
- Android开源框架ViewPagerIndicator的基本使用
转载本博客请注明出处:点击打开链接 http://blog.csdn.net/qq_32059827/article/details/52495647 很多新闻资讯类的app都有一些共性,那就是 ...
- Android百大框架排行榜
Android百大框架排行榜 15类Android通用流行框架 - 流风,飘然的风 - 博客园https://www.cnblogs.com/zdz8207/p/android-opensource- ...
- 2017年Android百大框架排行榜
框架:提供一定能力的小段程序 >随意转载,标注作者"金诚"即可 >本文已授权微信公众号:鸿洋(hongyangAndroid)原创首发. >本文已经开源到Gith ...
- android 优秀框架整理
程序员界有个神奇的网站,那就是github,这个网站集合了一大批优秀的开源框架,极大地节省了开发者开发的时间,在这里我进行了一下整理,这样可以使我们在使用到时快速的查找到,希望对大家有所帮助! 1. ...
- 2017年Android百大框架排行榜(转)
一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由.网络层.UI层.通信层或其他单一功能的框架 混合开发框架:提供开发hybrid app.h5与webview结合能力.web app能力的框架 ...
- Android开源框架ViewPageIndicator和ViewPager实现Tab导航
前言: 关于使用ViewPageIndicator和ViewPager实现Tab导航,在开发社区里已经有一堆的博客对其进行了介绍,假设我还在这里写怎样去实现.那简直就是老生常谈,毫无新奇感,并且.我也 ...
- Android 开源框架Universal-Image-Loader学习
Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用 Android 开源框架Universal-Image-Loader完全解析(二)--- 图片 ...
- Android 数据库框架OrmLite的使用(一)
在这里记录下最基本的用法,官网上可了解相关的介绍. 1.下载OrmLite jar 在下载android的:ormlite-android-4.48.jar和ormlite-core-4.48.jar ...
- Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读
转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/39057201),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...
随机推荐
- bzoj 1898
1898: [Zjoi2005]Swamp 沼泽鳄鱼 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1197 Solved: 661[Submit][S ...
- Extjs 4 MVC中全局配置文件
Extjs 4 Config和Mixins http://kldn.iteye.com/blog/1386622 http://www.fengfly.com/html/JavaScript/ExtJ ...
- mybatis 基础详解
转 https://www.cnblogs.com/Mr-Kenson/p/8124680.html mybatis 是一个开源的 用于对数据库操作的框架, 读者基本都大体了解其基本功能, 我就不多解 ...
- UVa 1471 Defense Lines (二分+set优化)
题意:给定一个序列,然后让你删除一段连续的序列,使得剩下的序列中连续递增子序列最长. 析:如果暴力枚举那么时间复杂度肯定受不了,我们可以先进行预处理,f[i] 表示以 i 结尾的连续最长序列,g[i] ...
- bzoj 2087: [Poi2010]Sheep【凸包+极角排序+dp】
首先处理处理出来哪些边能连--能把羊分成两个偶数部分的,实现是在凸包上枚举极点,极角排序,枚举凸包上点对判断两边羊的个数的奇偶即可,设可以连边为v[i][j]=1 然后设f[i][j]为从i到j个凸包 ...
- 小程序 获取地理位置-- wx.getLocation
话不多说直接上栗子 //首先声明变量data:{ showLocationAuth:fasle } //这是第一种逻辑实现方式 点击按钮//当第一次点击授权按钮,用户取消授权之后,就会显示 授权当前定 ...
- 关于python安装lxml插件的问题
文章只是介绍自己安装时从安装不上到安装后报错,再到安装成功的心路历程,并不代表广大欧皇也会会出现同类型的问题,也不是总结和汇总各种出问题的原因. 直接进入正题,首先我这边是win环境,电脑上装的是py ...
- CodeForces 923C Perfect Security
C. Perfect Security time limit per test3.5 seconds memory limit per test512 megabytes inputstandard ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- SSRS域账号下 User 'XXX' does not have required permissions的处理方法
SSRS安装完成后,点击Report Manager URL,提示:User 'XXX' does not have required permissions. Verify that suffici ...