以launcher为例说明自定义控件的属性:

1、在layout里面定义控件,如:

<com.junction.launcher.DragLayer

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:launcher="http://schemas.android.com/apk/res/com.junction.launcher"

android:id="@+id/drag_layer" android:layout_width="match_parent" android:layout_height="match_parent">

<com.android.launcher.Workspace

android:id="@+id/workspace"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

launcher:defaultScreen="1">


<include android:id="@+id/cell1" layout="@layout/workspace_screen" />

<include android:id="@+id/cell2" layout="@layout/workspace_screen" />

<include android:id="@+id/cell3" layout="@layout/workspace_screen" />

</com.android.launcher.Workspace>

2、该控件workspace下面有一个属性是launcher:defaultScreen,这属性不是ViewGroup(workspace类是继承于ViewGroup)所定义的属性,那么我们可以在\res\values里面的attrs.xml里面定义

具体的定义方法如下:

<resources>

<declare-styleable name="Workspace">

<attr name="defaultScreen" format="integer"/>

</declare-styleable>

</resources>

引用方法是先申明xmlns:launcher="http://schemas.android.com/apk/res/com.junction.launcher"(R.java),这样就可以使用launcher:defaultScreen。

3、这样我们在Workspace的类里面就可以去除在layout里面对该属性的赋值,方法如下:

Int mDefaultScreen;

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);

mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);

a.recycle();

++++++++++++++++++++++++++++++

自己案例:可看一个gifPlayer的demo程序。

其他案例:http://blog.csdn.net/Android_Tutor/archive/2010/04/20/5508615.aspx

++++++++++++++++++++++++++++++

转载自:http://blog.csdn.net/tinafhx/archive/2010/02/05/5290878.aspx

更多相关文章

  1. Android中两种设置全屏的方法
  2. android intent.setType("type");的含义
  3. android4.2 修改设置背景
  4. Android(安卓)模糊搜索rawquery bind or column index out of ra
  5. 转 Android中shape中的属性大全
  6. RelativeLayout相对布局中的属性
  7. Android(安卓)模糊搜索rawquery bind or column index out of ra
  8. android ui 之 Styles 和 Theme
  9. android 动画

随机推荐

  1. 像SpringMVC一样在Android上做Web开发
  2. 如何从云端推送消息到手机 (Android(安卓
  3. Android(安卓)悬浮窗权限各机型各系统适
  4. Android系列之Android系列之如何成为Andr
  5. RN系列:RN使用Android原生控件或自定义组
  6. 个人开发者做一款Android(安卓)App,androi
  7. 关于android常用的按下高亮的展示
  8. Android 学习1----控件的学习
  9. Android的图形显示原理(GDI)一
  10. Android 事件分发机制源码