Most of the time you want to design a nice Android UI, the controls that you use with Android don't meet our needs. Consider customizing the control, display Class View in the Android interface, and implement our graph drawing by inheriting extension rewrite related methods.
First we need to understand the bottom of the view class implementation, in the SDK we can see the view directly inherit from the Java base class object, the implementation of graphics and key events Drawable.callback Keyevent.callback related methods, we mainly implement the internal OnDraw method, the relevant interface calculation can rewrite the Onmeasure method, for the relevant keys can overload onkeydown, OnKeyUp and Ontouchevent and so on, the following Android Development network is represented as an example.
public class Cwjview Extendsview
{
Public Cwjview
{
This (context,null);
}
Public Cwjview (Context Context,attributeset attrs)
{
This (context,attrs,0);
}
Public Cwjview (Context Context,attributeset attrs,int Defstyle)
{
Super (Context,attrs,defstyle);
Here is the construction of this class, where related initialization can add code
}
@Override
PROTECTD void OnDraw (Canvas Canvas)
{
Super (canvas);
The key to the drawing, you can see that already contains a canvas handle, you can directly through the canvas class we talked about the relevant operations, complete examples, you can refer to the Android SDK Example Snake snake Game implementation.
}
}
For updates to the view class, we update a rect rectangle area directly by calling invalidate (int l,int r,int r,int b), and we update the interface with the need to invoke postinvalidate in the thread.