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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:00:42+00:00 2026-05-27T06:00:42+00:00

Friends, i want to make a seamless background as a custom view component. the

  • 0

Friends,

i want to make a seamless background as a custom view component.

the problem i figured out during debugging,

the first time i call invalidate() within the thread my onDraw callback method is called.
The other times my thread is calling invalidate() the onDraw callback method is not called.

so its just running over the invalidate() method , like it would not even exist.

The application displays the seamlessbackground png. But as static. it not gets updated.

I post all my code because the bug might be outside of the thread, where invalidate() is located or outside the onDraw method.

apprechate any kind of help! so THX

              public class MyBringBackSurface extends View implements Runnable {

Bitmap bitmapResource;
int leftFrameX, rightFrameX, startX, stopX, bitmapPixelWidth,
        bitmapPixelHight;
int pixelPerFrame = 10;
int framerate = 100;
int threadSleepTime;
int offsetYInPixel = 200;
Thread ourthread = null;
boolean isrunning = false;

Canvas c;

public MyBringBackSurface(Context context) {
    super(context);

    init();

}

public MyBringBackSurface(Context context, AttributeSet attrs) {
    super(context, attrs);

    init();

}

public MyBringBackSurface(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    init();

}

private void init() {


    // Set up Bitmap Resource

    bitmapResource = BitmapFactory.decodeResource(getResources(),
                    R.drawable.simelessbackground);


 //  c = new Canvas(bitmapResource);


    // Implementing leftFrameX and rightFrameX
    leftFrameX = 0;
    rightFrameX = bitmapResource.getWidth();

    // Calculating the Thread sleep time
    threadSleepTime = 1000 / framerate;



}

public void pause() { // destroy the currently running thread because
                        // anyways in the on resume will be created a
                        // new one again

    isrunning = false;
    while (true) {

        try { // goes through this thread until our thread died
            ourthread.join(); // Blocks the current Thread
                                // (Thread.currentThread()) until the
                                // receiver finishes its execution and
                                // dies.
        } catch (InterruptedException e) {

            e.printStackTrace();
        }
        break;
    }


}

public void resume() {

    isrunning = true;
    ourthread = new Thread(this);

    ourthread.start();

}

public void run() {

    while (isrunning) {

        try {
            Thread.sleep(threadSleepTime);
            // formula is 1000/ sleep time (here 5) = frame rate
        } catch (InterruptedException e) {

            e.printStackTrace();
        }

        invalidate();

        // Add pixelPerFrame and draw again
        leftFrameX = leftFrameX - pixelPerFrame;
        rightFrameX = rightFrameX - pixelPerFrame;

        // if picture is completely out of the screen, start over again
        if (leftFrameX <= -bitmapResource.getWidth()) {
            leftFrameX = 0;
            rightFrameX = bitmapResource.getWidth();
        }
    }
}

/**
 * Render the text
 * 
 * @see android.view.View#onDraw(android.graphics.Canvas)
 */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);


    canvas.drawRGB(255, 255, 255);

    // Draw Rectangle 1250 pixel
    Rect rect1000 = new Rect();
    rect1000.set(0, 0, 1250, 20);
    Paint blue = new Paint();
    blue.setColor(Color.BLUE);
    canvas.drawRect(rect1000, blue);

    // Draw first Bitmap
    Rect rectBitmapSource = new Rect(0, 0, bitmapResource.getWidth(),
            bitmapResource.getHeight());
    Rect rectBitmapDestinationFirst = new Rect(leftFrameX, offsetYInPixel,
            rightFrameX, offsetYInPixel + bitmapResource.getHeight());
    canvas.drawBitmap(bitmapResource, rectBitmapSource,
            rectBitmapDestinationFirst, null);

    // Draw second Bitmap

    Rect rectBitmapDestinationSecond = new Rect(
            (leftFrameX + bitmapResource.getWidth()), offsetYInPixel,
            (rightFrameX + bitmapResource.getWidth()), offsetYInPixel
                    + bitmapResource.getHeight());
    canvas.drawBitmap(bitmapResource, rectBitmapSource,
            rectBitmapDestinationSecond, null);



}

}

  • 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-27T06:00:43+00:00Added an answer on May 27, 2026 at 6:00 am

    I figured out the answer after going throught the googledocs.

    if you want to invalidate a View from outside of the UI-Thread you have to use the
    postinvalidate() command instead of invalidate().

    Thats it. It will work like charme!!!

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

Sidebar

Related Questions

I have two paragraphs wrapped in a div. I want to make the first
I want to make a friends list in my online game. I am not
Hey Friends I want to make a form builder using Yii. For that I
Hi Friends I Want to make a simple gaming Application in which the user
I'm working on mobile ipv6 in java and want to make custom ipv6 packets.
I want to create a table of friends with personal information and log on
Friends, If I want to know about the new features of Oracle 11gR2 Database
I often want to send sample apps to friends & colleages that work with
I have a database table that i want to allow my friends to update.
Rather than just grabbing the user's friends' emails, I want to show their list

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.