res/values/attrs.xml
<declare-styleable name="CellLayout">
<!-- The width of a single cell -->
<attr name="cellWidth" format="dimension" />
<!-- The height of a single cell -->
<attr name="cellHeight" format="dimension" />
.....
</declare-styleable>
res/layout-port/workspace_screen.xml
<com.android.launcher.CellLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
launcher:cellWidth="80dip"
launcher:cellHeight="96dip"
....
/>
src/com.android.launcher.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);
mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
.....
}
根据颜色看, 应该很清晰:
1. 蓝色部分是自己定义的styleable和attr的名称, 代码和XML里要一致;
2. 绿色部分是自定义的命名空间名称, 也只要上下保持一致即可;
3. 红色部分是View所在的包名, 不允许有误.
参考:http://blog.csdn.net/Android_Tutor/archive/2010/04/21/5508615.aspx
分享到:
相关推荐
Android自定义View——自定义插值器和估值器实现向上抛体运动
Android自定义View——多边形网格属性图
在自定义View时,我们通常会去重写onDraw()方法来绘制View的显示内容。如果该View还需要使用wrap_content属性,那么还必须重写onMeasure()方法。另外,通过自定义attrs属性,还可以设置新的属性配置值。
本程序——使用View绘制的一个日历界面+记事本操作,可直接插入手机系统备忘录,设置系统定时提醒,等。
Android自定义View——拼手气转盘 Android自定义View——拼手气转盘
Android自定义View——拼手气转盘 Android自定义View——拼手气转盘
博客地址:http://blog.csdn.net/xiaohao0724/article/details/54572605
Android自定义View——贝塞尔曲线实现直播点赞效果 Android自定义View——贝塞尔曲线实现直播点赞效果
Android自定义View——折线统计图
[android 自定义view的使用(最佳demo——返回标题栏)](http://blog.csdn.net/double2hao/article/details/50209249) [android 自定义控件(底部icon点击效果)]...
仿真书籍翻页效果BookPageView简介:实现了仿真翻页效果,教程完整地描述了翻页原理分析到性能优化的过程教程博客:Android自定义View——从零开始实现书籍翻页效果(一) Android自定义View——从零开始实现书籍...
Android 自定义view-仿新浪微博#话题#插入EditText 博客地址http://blog.csdn.net/u014702653/article/details/52799715
Android自定义View——实现字母导航栏
Android自定义View——彩色圆环统计图
Android自定义标签view——可自动换行,该项目从github上下载下来,经测试效果非常不错,下载后可以直接运行使用。
ViewGroup存在的目的就是为了对其子View进行管理,为其子View添加显示、响应的规则。因此,自定义ViewGroup通常需要重写onMeasure()方法来对子View进行测量,重写onLayout()方法来确定子View的位置,重写...
共同学习共同进步
Android自定义View——饼图,可参考博客http://blog.csdn.net/liuwan1992/article/details/52637259
Android自定义View——贝塞尔曲线实现水波纹进度球 Android自定义View——贝塞尔曲线实现水波纹进度球
博客《PullScrollView详解(一)——自定义控件属性》对应源码,博客地址:http://blog.csdn.net/harvic880925/article/details/46537767