Refer:
Http://blog.sina.com.cn/s/blog_4b50130d0100u0uk.html
Http://blog.csdn.net/hearrt/article/details/7001358
The ondraw () method of the custom view is not executed.
When we need to create a class that inherits the view directly or indirectly, so as to override the ondraw () method and implement custom view painting, we often find that the ondraw method is not correctly executed.
You need to add the following sentence to the structure data of the view directly or indirectly:
Setwillnotdraw (false );
This mark is not set in the view. However, some sub-classes such as viewgroup of a view can be set. Typically, if you have implemented the ondraw (canvas) method, you need to clear this tag.
1. Implement a container to do this:
[Java]
View plaincopyprint?
- Public class customframelayout extends framelayout {
- Private Static final string tag = "customframelayout ";
- Public customframelayout (context ){
- Super (context );
- This. setwillnotdraw (false); // required
- }
- Public void ondraw (canvas ){
- Super. ondraw (canvas );
- Drawsomething (canvas );
- }
- }
Public class customframelayout extends framelayout {Private Static final string tag = "customframelayout"; Public customframelayout (context) {super (context); this. setwillnotdraw (false); // required} public void ondraw (canvas) {super. ondraw (canvas); drawsomething (canvas );}}
When the constructor does not include this. setwillnotdraw (false), The ondraw function is never called until it is added.
Carefully read the description of the ondraw function:
Public void setwillnotdraw (Boolean
Willnotdraw) since: API Level 1
If this view doesn' t do any drawing on its own, set this flag to allow further optimizations. by default, this flag is not set on view, but cocould be set on some view subclasses such as viewgroup. typically, If you overrideonDraw(Canvas)You
Shocould clear this flag.
Parameters
| Willnotdraw |
Whether or not this view draw on its own |
Setwillnotdraw (false). 2. If you have two containers A and A, A is placed in. If setwillnotdraw (false) is set for both containers, you will see a "miracle": the added controls in a are not transparent, at this time, do not doubt that your control image is not transparent, because you set setwillnotdraw (false) for container a and try to remove it. The problem is OK.
Share:
Previous Article: SVN update Problems
Next article: Wireless debugging for Android phones
Refer:
Http://blog.sina.com.cn/s/blog_4b50130d0100u0uk.html
Http://blog.csdn.net/hearrt/article/details/7001358
The ondraw () method of the custom view is not executed.
When we need to create a class that inherits the view directly or indirectly, so as to override the ondraw () method and implement custom view painting, we often find that the ondraw method is not correctly executed.
You need to add the following sentence to the structure data of the view directly or indirectly:
Setwillnotdraw (false );
This mark is not set in the view. However, some sub-classes such as viewgroup of a view can be set. Typically, if you have implemented the ondraw (canvas) method, you need to clear this tag.
1. Implement a container to do this:
[Java]
View plaincopyprint?
- Public class customframelayout extends framelayout {
- Private Static final string tag = "customframelayout ";
- Public customframelayout (context ){
- Super (context );
- This. setwillnotdraw (false); // required
- }
- Public void ondraw (canvas ){
- Super. ondraw (canvas );
- Drawsomething (canvas );
- }
- }
Public class customframelayout extends framelayout {Private Static final string tag = "customframelayout"; Public customframelayout (context) {super (context); this. setwillnotdraw (false); // required} public void ondraw (canvas) {super. ondraw (canvas); drawsomething (canvas );}}
When the constructor does not include this. setwillnotdraw (false), The ondraw function is never called until it is added.
Carefully read the description of the ondraw function:
Public void setwillnotdraw (Boolean
Willnotdraw) since: API Level 1
If this view doesn' t do any drawing on its own, set this flag to allow further optimizations. by default, this flag is not set on view, but cocould be set on some view subclasses such as viewgroup. typically, If you overrideonDraw(Canvas)You
Shocould clear this flag.
Parameters
| Willnotdraw |
Whether or not this view draw on its own |
Setwillnotdraw (false). 2. If you have two containers A and A, A is placed in. If setwillnotdraw (false) is set for both containers, you will see a "miracle": the added controls in a are not transparent, at this time, do not doubt that your control image is not transparent, because you set setwillnotdraw (false) for container a and try to remove it. The problem is OK.