res/values/attrs.xml <declare-styleable name="CellLayout"><!-- The width of a single cell --><attr name="cellWidth" format="dimension"></attr><!-- The height of a single cell --><attr name="cellHeight" format="dimension"></attr> ..... </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" ....></com.android.launcher.celllayout> 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 http://hi.baidu.com/lck0502/blog/item/8d4e453f80cf43cf7c1e714b.html

更多相关文章

  1. 整理出15个Android很有用的代码片段(技巧)
  2. android学习笔记一
  3. Android(安卓)颜色渲染(六) RadialGradient 环形渲染
  4. android 自定义Dialog弹出提示框
  5. Android(安卓)开发工具集合 http://www.androiddevtools.cn/
  6. Android(安卓)Material Design(一)史上最全的材料设计控件大全
  7. 操作Android中联系人,通话记录,短息,的URI
  8. Android中对TextView中的部分内容的字体样式的设置方法
  9. Android(安卓)M新控件知识整理

随机推荐

  1. 智能手机软件平台 Android(安卓)VS iPhon
  2. android 切换activity动画
  3. android adapter 异步加载图片
  4. Android之Fragment动态添加和移除Fragmen
  5. Android(安卓)USB Host and Accessory
  6. StringTokenizer用法
  7. Android(安卓)代码实现的动画
  8. Android(安卓)通过HTTP POST 上传图片文
  9. Android(安卓)Dex文件结构
  10. Android(安卓)中 上下文Context理解