Take launcher as an example to describe the attributes of a custom control:
1. Define controls in layout, for example:
<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. There is an attribute under the workspace of the control:Launcher: defaultscreenThis attribute is not defined by viewgroup (workspace class is inherited from viewgroup), so weIt can be defined in attrs. XML in \ res \ values.
The specific definition method is as follows:
<Resources>
<Declare-styleable name = "workspace">
<ATTR name = "defaultscreen" format = "integer"/>
</Declare-styleable>
</Resources>
The reference method isDeclare xmlns: launcher first= "Http://schemas.android.com/apk/res/com.junction.launcher" (R. Java) so you can useLauncher: defaultscreen.
3. In this way, we can remove the value assigned to this attribute in layout in the workspace class. The method is as follows:
Int mdefaultscreen;
Typedarray A = context. obtainstyledattributes (attrs, R. styleable. workspace, defstyle, 0 );
Mdefaultscreen = A. getint (R. styleable. workspace_defaultscreen, 1 );
A. Recycle ();
++
Your own case: You can see a GIF player demo program.
Other case: http://blog.csdn.net/Android_Tutor/archive/2010/04/20/5508615.aspx
++
Reprinted from: http://blog.csdn.net/tinafhx/archive/2010/02/05/5290878.aspx