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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:56:26+00:00 2026-06-12T18:56:26+00:00

I have a SurfaceView and I want the Bitmap Logo inside it in the

  • 0

I have a SurfaceView and I want the Bitmap Logo inside it in the canvas to be movable

What I’m doing wrong ?

static float x, y;
Bitmap logo;

SurfaceView ss = (SurfaceView) findViewById(R.id.svSS);   
    logo = BitmapFactory.decodeResource(getResources(), R.drawable.logo);

    x = 40;
    y = 415;
    ss.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent me) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        switch(me.getAction()) {
        case MotionEvent.ACTION_DOWN:
            x = me.getX();
            y = me.getY();
            break;
        case MotionEvent.ACTION_UP:
            x = me.getX();
            y = me.getY();
            break;
        case MotionEvent.ACTION_MOVE:
            x = me.getX();
            y = me.getY();
            break;
            }
        return true;
        }
    });

public class OurView extends SurfaceView implements Runnable{

    Thread t = null;
    SurfaceHolder holder;
    boolean isItOK = false;


    public OurView(Context context) {
        super(context);
        holder = getHolder();

    }
    public void run (){
        while (isItOK == true){
            //canvas DRAWING
            if (!holder.getSurface().isValid()){
                continue;
            }
            Canvas c = holder.lockCanvas();
            c.drawARGB(255, 200, 100, 100);
            c.drawBitmap(logo, x,y,null);
            holder.unlockCanvasAndPost(c);
        }
    }
    public void pause(){
        isItOK = false;
        while(true){
            try {
                t.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            break;
        }
        t = null;
    }
    public void resume(){
        isItOK = true;
        t = new Thread(this);
        t.start();

    }
}

Now the surface view is just black .. nothing happens also its not colored 200, 100, 100

  • 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-12T18:56:27+00:00Added an answer on June 12, 2026 at 6:56 pm

    You might forget to implement onDraw(Canvas c) method in your OurView class, and move the onTouchEvent inside the class.

    The class structure should like this:

    public class OurView extends View implements Runnable {
    
    //...your runnable stuff here
    //...Runnable stuff means your run(), pause() etc.
    
      public OurView(Context context) {
        super(context);
        //your constructor stuff here
        // your constructor, do you find the similar stuff to this you wrote? That's your constructor, so you can just add:
        holder = getHolder();
    }
    
    protected void onDraw (Canvas c) {
    
        c.drawBitmap(bitmap, x, y);
    //set colour, draw bitmap here, onDraw() will be called automatically, so just call invalidate(); when you need to "refresh" the view
    }
    
    public boolean onTouchEvent(MotionEvent e) {
        float x = e.getX();
        float y = e.getY();
    
        swith(e.getAction()) {
        case MotionEvent.ACTION_DOWN:
         ...
        }
    }
    }
    

    For more explicit example and reference please go:

    Implementing a Custom View

    Custom Components

    Hope it could help you.

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

Sidebar

Related Questions

HI! I have a surfaceView inside a horizontal scrollview that I want to fill
I have a canvas that contains several bitmap images, I want the user to
I have an XML layout and want to add my own custom SurfaceView to
In my game, I have a surfaceView and I'm using a bitmap of resolution
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have an Application in that I want to capture video using Surfaceview and
I want to create a message with Toast inside a SurfaceView class. With this
In my application, I have a SurfaceView showing a Camera preview, and want to
I want to put a transparent SurfaceView on top of an ImageView. I have
I'm developing a 2d Game using Canvas/Surfaceview and have a problem with thread. So

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.