自定义ViewPagerIndicator(下)
2015-09-08 22:14
489 查看
由于有些参数定义为成员变量,不好复制,具体请参考源码。
(1) 在values目录中创建attrs.xml( 技巧:拷贝ApiDemos\res\values\attrs.xml,保留labelview,删除其他进行编辑比较快)
(2) 在自定义控件两个参数构造方法中解析属性,并设置到画笔和画布上
(3)在需要此控件的布局上使用它
源码地址:http://download.csdn.net/download/sjc1010592550/9090189
(1) 在values目录中创建attrs.xml( 技巧:拷贝ApiDemos\res\values\attrs.xml,保留labelview,删除其他进行编辑比较快)
<resources> <declare-styleable name="PagerIndicator"> <attr name="selectedColor" format="color" /> <attr name="strokeWidth" format="dimension" /> <attr name="unselectedColor" format="color" /> <attr name="radius" format="dimension" /> </declare-styleable> </resources>
(2) 在自定义控件两个参数构造方法中解析属性,并设置到画笔和画布上
public PagerIndicator(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerIndicator); colorSelect = a.getColor( R.styleable.PagerIndicator_selectedColor, Color.GRAY); colorUnselect = a.getColor( R.styleable.PagerIndicator_unselectedColor, Color.RED); strokeWidth = a.getDimension( R.styleable.PagerIndicator_strokeWidth, 3); radius = a.getDimension( R.styleable.PagerIndicator_radius, 15); a.recycle();// 释放内存 initPaint(); }
(3)在需要此控件的布局上使用它
<com.xinbo.demo.PagerIndicator xmlns:indicator="http://schemas.android.com/apk/res-auto" android:id="@+id/pagerIndicator1" indicator:selectedColor="#0000FF" indicator:unselectedColor="#00FF00" indicator:strokeWidth="1dp" indicator:radius="10dp" android:layout_width="match_parent" android:background="#40000000" android:layout_gravity="bottom" android:layout_height="80dp" />
源码地址:http://download.csdn.net/download/sjc1010592550/9090189
相关文章推荐
- PHP实现留言本代码
- 某点处的导函数值+c语言
- HDU 4010 动态树LCT学习
- hdu5011Game nim博弈
- UVA-1220 Party at Hali-Bula (树的最大独立集)
- C++ nontrival class 值传递的机制。
- C++ nontrival class 值传递的机制。
- ThinkPad T430i黑苹果Yosemite 10.10.3成功显卡驱动
- WebKit官方又开始发布源代码压缩包了
- 1083. List Grades (25)
- 简单二维数组转置问题
- 线程池原理Java
- .net重启iis线程池和iis站点程序代码分享
- MySQL博文归类
- BOM和DOM
- Trie树:统计词频、排序、查找
- 发送文件
- mysql数据库常用的函数
- cocos2D-x 学习之路(二)
- OpenJDK与HashMap……放心地教这个老家伙一些新(非堆!)技巧