Android UI development topic (4) view self-painted controls

Source: Internet
Author: User
In many cases, if you want to design a beautiful Android UI, you must consider the self-painted controls to display class views on the android interface, we can use the inheritance extension to override related methods to draw our graphics. First, we need to understand the underlying implementation of the View class. In the SDK, we can see that the view directly inherits from the Java base class object and implements drawing and button event drawable. callback keyevent. callback-related methods: We mainly implement the ondraw method in self-painting. For interface computing, we can rewrite the onmeasure method. For related buttons, We can reload onkeydown, onkeyup, and ontouchevent, the following Android development network is represented by an instance.
Public class cwjview extendsview
{
Public cwjview (context)
{
This (context, null );
}
Public cwjview (context, attributeset attrs)
{
This (context, attrs, 0 );
}
Public cwjview (context, attributeset attrs, int defstyle)
{
Super (context, attrs, defstyle );
// Here is the construction of this class, and related initialization can be added here Code
}
@ Override
Protectd void ondraw (canvas)
{
Super (canvas );
// The Key to drawing. You can see that a canvas handle is included. You can perform related operations directly through the canvas class we mentioned earlier. Complete example, you can refer to the example in the android SDK to implement the Snake snake game.
}
}
For update of the View class, call invalidate (int l, int R, int R, int B) to update a rect rectangular area or update all, at the same time, we need to call postinvalidate in the thread to update the interface.

This article is transferred fromWww.35java.com

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.