Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:03:05+00:00 2026-06-16T05:03:05+00:00

At first, I created a custom view that drew itself by overriding the onDraw()

  • 0

At first, I created a custom view that drew itself by overriding the onDraw() method. This turned out to be impractical because of the large amount of views I needed to create. So I’ve created a custom ViewGroup that draws each of it’s childs with the onLayout() method.

I’ve read in the android documentation that the child view should implement a layout() method. But the child view I have made, uses the onDraw method to draw itself. How should I handle this? Should I get rid of the onDraw() method? And could anyone give me an example of how the layout() method works and how I should ‘convert’ my onDraw() method to a layout() method?

my current onDraw() method looks like this:

protected void onDraw(Canvas canvas)
    {
        super.onDraw(canvas);

        //Draw Border.
        canvas.drawRect(mCellBounds, mBorderPaint);

        //Draw Background.
        canvas.drawRect(mBackgroundBounds, mBackGroundPaint);

        //Draw Value if not 0.
        if(Value != 0)
            canvas.drawText(Integer.toString(Value), ValueX, ValueY, mNumberPaint);

        //Draw Notes if Value == 0.
        else
        {
            for(int i = 0 ; i < 9 ; i++)
                if(NoteList[i])
                    canvas.drawText(Integer.toString(i), NoteX + ((i%3) * NoteMeasureX), NoteY + ((i/3) * NoteMeasureY), mNotePaint);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:03:06+00:00Added an answer on June 16, 2026 at 5:03 am

    So I’ve created a custom ViewGroup that draws each of it’s childs with
    the onLayout() method.

    I don’t see how you draw the ViewGroup‘s children in its onLayout method. That method should be used to position the children on the screen.

    I’ve read in the android documentation that the child view should
    implement a layout() method

    That method is already implemented, you call it with the right values so the View will know where it should be placed on the screen.

    Should I get rid of the onDraw() method?

    If you want to actually see something you shouldn’t ignore the onDraw method.

    And could anyone give me an example of how the layout() method works
    and how I should ‘convert’ my onDraw() method to a layout() method?

    You don’t convert the onDraw method to the layout method. As an example, I made a small sample consisting of a custom ViewGroup along with a custom child View. The custom ViewGroup it will placed the two(expected children) like in the image below(each child will have half the width and height of the parent):

    custom ViewGroup

    You can find the sample here. I hope it helps you.
    You could also have a look at the source code for the SDK layouts(like the simple FrameLayout) to see how they do their magic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Created Custom view and overridden it's onDraw(). Without Overriding onMeasure() canvas occupies the entire
What I've done is created a custom TableCell view that gets populated with information
I have created a custom view hierarchy in an XIB that I want to
I've a custom table view cell that I created using XIB: I've also linked
I have a table view. I have created a method that takes all the
I have some problems with my first Open Graph custom action: I've created a
I am following this example (First comment), How to create a custom ListView with
First,I created a hidden frame like this: var oHiddenFrame = null; if(oHiddenFrame == null){
I've created custom UIView with backgroundImage for UITableViewCell selected state like that: UIView *selectedBgView
I've created a UIImagePicker / camera view, with a toolbar and custom button for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.