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 6733981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:50:05+00:00 2026-05-26T10:50:05+00:00

I have a SurfaceView where I’m setting a background color and an image like

  • 0

I have a SurfaceView where I’m setting a background color and an image like so:

BitmapDrawable tiledBackground = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.background));
tiledBackground.setTileModeX(Shader.TileMode.REPEAT);
tiledBackground.setColorFilter(0xaacceeff, PorterDuff.Mode.DST_OVER);
this.setBackgroundDrawable(tiledBackground);

I also have an animation thread where I’m drawing an image (successively adjusting its x coordinate so that it appears to move to the left). The background image is a transparent PNG and so some parts of it are transparent. It appears that the image I’m drawing from the thread appears below the background drawable on the SurfaceView. How can I have it appear on top of the background? I’m drawing the image like so:

private void doDraw(Canvas canvas) {
    canvas.drawColor(Color.BLACK);
    canvas.drawBitmap(missile, x, getHeight() - 95, paint);
    canvas.restore();
}

missile and paint are initialized in the constructor of the thread to:

missile = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.missile));
paint = new Paint();
  • 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-26T10:50:06+00:00Added an answer on May 26, 2026 at 10:50 am

    Each call to doDraw should draw everything you want to be displayed, including the background.

    // Add to initializer
    tiledBackground = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.background));
    tiledBackground.setTileModeX(Shader.TileMode.REPEAT);
    tiledBackground.setColorFilter(0xaacceeff, PorterDuff.Mode.DST_OVER);
    
    private void doDraw(Canvas canvas) {
        canvas.drawColor(Color.BLACK);
        // Create a rectangle (just holds top/bottom/left/right info)
        Rect drawRect = new Rect(); 
    
        // Populate the rectangle that we just created with the drawing area of the canvas.
        canvas.getClipBounds(drawRect);
    
        // Make the height of the background drawing area equal to the height of the background bitmap
        drawRect.bottom = drawRect.top + tiledBackground.getBitmap().getHeight();
    
        // Set the drawing area for the background.
        tiledBackground.setBounds(drawRect);
    
        tiledBackground.draw(canvas);
        canvas.drawBitmap(missile, x, getHeight() - 95, paint);
        canvas.restore();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SurfaceView that is resposible for drawing a Bitmap as a background
how to clear the surfaceView in android? I have a class like this -
In my application, I have a SurfaceView showing a Camera preview, and want to
I have a custom View extending SurfaceView. The XML layout is <com.myPackage.MyCustomView android:id=@+id/mycview android:layout_width=fill_parent
I have two Activities, both have an inner class SurfaceView, which has an inner
I currently have a SurfaceView that is in Landscape mode. Currently I am trying
I'm having a problem getting a bitmap to rotate properly. I have a SurfaceView
I have an Application in that I want to capture video using Surfaceview and
I have a dialog box which appears on top of a SurfaceView. I would
I have my main Activity, it starts with a custom SurfaceView called DrawView being

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.