The ondraw function of view is not called.

Source: Internet
Author: User

 

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?
  1. Public class customframelayout extends framelayout {
  2. Private Static final string tag = "customframelayout ";
  3. Public customframelayout (context ){
  4. Super (context );
  5. This. setwillnotdraw (false); // required
  6. }
  7. Public void ondraw (canvas ){
  8. Super. ondraw (canvas );
  9. Drawsomething (canvas );
  10. }
  11. }
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?
    1. Public class customframelayout extends framelayout {
    2. Private Static final string tag = "customframelayout ";
    3. Public customframelayout (context ){
    4. Super (context );
    5. This. setwillnotdraw (false); // required
    6. }
    7. Public void ondraw (canvas ){
    8. Super. ondraw (canvas );
    9. Drawsomething (canvas );
    10. }
    11. }
    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.

    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.