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

  • SEARCH
  • Home
  • 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 7658629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:13:37+00:00 2026-05-31T13:13:37+00:00

I am building a paint application for android. Extending the FingerPaint application sample provided

  • 0

I am building a paint application for android. Extending the FingerPaint application sample provided with the SDK. However, unlike FingerPaint, I’m using SurfaceView with a separate rendering thread to draw to the surface. All this is very standard and straightforward. Working well. I want to, however, give a White coloured background to the painting surface, so it’s like drawing on a white paper. The default background is black coloured.
The thread of my surface view, calls the onDraw() method of the view.

The problem I’m facing here is, if I set a background colour or background resource to my SurfaceView, this background overwrites the previous drawing of the surface, when the view is rendered the next time. I will explain this with an example:

Suppose I set the background to white colour. Now, the application starts, with my SurfaceView having the white colour. Ok, so far good. Now, I draw a red coloured line on this surface, with my finger. The line is now shown on the white surface. Good. Now, this is supposed to be a painting app, and suppose I want to draw a car. So, then, I draw my 2nd red line, with my finger. The 2nd line is drawn on the screen, but the 1st one, which I drew previously, vanishes. That is, because I have set some background to my SurfaceView, the background is drawn again, thus overwriting the 1st line that was drawn. Now the screen shows only the 2nd line drawn.

Obviously, I do not want this to happen. The code works perfectly, when I don’t attempt to change the background (that is, both lines are shown, on a default black background, no background effectively). But when I set some desired background, this thing happens. Is there a way to somehow have a static background, that is not drawn every time? I want the background to be drawn only once, all the subsequent drawings should happen on this background. I don’t want the android runtime , to draw the background, every time it draws my view, thus overwriting all drawing present on that view, from previous renderings. Any way to work around this?

The things I have tried, to achieve this are:

  1. Setting the background colour of my SurfaceView using android:background in XML.

  2. Doing the above, using the concept of style. (specifying a style value and referencing it in the layout file). The style just defines the background colour as #FFFFFFFF (white).

  3. Setting the style of 2, to the parent view of the SurfaceView (a RelativeLayout).

  4. Setting the style of 2, to the entire application, as a theme,using android:theme in my manifest file.

  5. Setting the background drawable of my SurfaceView to an image which is plain and white-coloured.

  6. Calling the setBackgroundColor for my SurfaceView from the code as, this.setBackgroundColor(Color.WHITE).

Thanks.

  • 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-05-31T13:13:37+00:00Added an answer on May 31, 2026 at 1:13 pm

    according to android’s doc:

    The surface is Z ordered so that it is behind the window holding its
    SurfaceView; the SurfaceView punches a hole in its window to allow its
    surface to be displayed. The view hierarchy will take care of
    correctly compositing with the Surface any siblings of the SurfaceView
    that would normally appear on top of it. This can be used to place
    overlays such as buttons on top of the Surface, though note however
    that it can have an impact on performance since a full alpha-blended
    composite will be performed each time the Surface changes

    so if you change the z order of surface view via:

    setZOrderOnTop(true);
    

    this will work, but then you cannot put any other view on top of surface view.

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

Sidebar

Related Questions

I am building my android ndk application by using ndk-build commend and it works
I am building a web application that needs to print directly from browser, however,
I am building an application using CoreData which will require me to store an
I'm building an Android application (as an Eclipse project) that needs to access a
I'm building the Android scanning app using zxing library. I have built the zxing
I'm building application, which paints raw bitmap images on label's hdc using StrechDIBits. ptr
I am building an application in JavaScript using ExtJS. As I add more functionality
I am building a small Android application which will add a cube on user's
I have an application building against Android 2.1 and I want to override the
I am building an iPhone application that will be using a weighted graph (probably

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.