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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:52:30+00:00 2026-06-08T04:52:30+00:00

I have a problem with simple drawing application on Android. Here’s my class which

  • 0

I have a problem with simple drawing application on Android.

Here’s my class which is extending SurfaceView:

public class SomeView extends SurfaceView implements SurfaceHolder.Callback {

private static SurfaceHolder surfaceHolder;
static Canvas canvas=null;
static Paint paint=new Paint();
float X,Y,X1,Y1;
static int mode=1;

public static void ClearAll(){
    canvas=surfaceHolder.lockCanvas(null);
    canvas.drawColor(Color.BLACK);
    surfaceHolder.unlockCanvasAndPost(canvas);
}

public SomeView(Context context,AttributeSet attrs) {
    super(context);
    getHolder().addCallback(this);
    paint.setColor(Color.WHITE);
    paint.setStyle(Style.FILL);
}


@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {   
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    this.surfaceHolder=holder;
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}

public boolean onTouchEvent(MotionEvent event)
{
    canvas=surfaceHolder.lockCanvas(null);
    if (mode==1){       
        canvas.drawCircle(event.getX(), event.getY(),10, paint);
    }
    if (mode==2){
        paint.setStrokeWidth(10);
        if (event.getAction()==MotionEvent.ACTION_DOWN){
            X=event.getX();
            Y=event.getY();
        }
        if (event.getAction()==MotionEvent.ACTION_UP){
            X1=event.getX();
            Y1=event.getY();
            canvas.drawLine(X, Y, X1, Y1, paint);
        }
    }
    surfaceHolder.unlockCanvasAndPost(canvas);
    return true;
}

}

mode=1 – is simple user’s touches tracing,

mode=2 – is straight-lines drawing

However, when I’m drawing in mode=2 the picture becomes weird:
Some lines disappear and after few more lines were drawn appears again. When I’m still touching the screen the canvas is blinking and showing all the lines were drawn since last ClearAll() call. If I stop touching only few lines are still visible.

What is the problem?

  • 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-08T04:52:32+00:00Added an answer on June 8, 2026 at 4:52 am

    SurfaceView used double buffering. Generally – on each cycle/action you have to draw every pixel you want to be visible on the canvas.
    Hope that helps.

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

Sidebar

Related Questions

Have a simple drawing application. The problem is in the coordinates ( redraw function):
I have a simple drawing application, with which you can color cells of a
I have this simple application in which a command like RECT 10 20 100
I have a prototype of a simple drawing application. When the user drags a
I have a drawing application developed in winforms C# which uses many System.Drawing.Bitmap object
I have problem with text drawing around Circle. I found great sample in C#
I have a simple problem with SQL SERVER charindex function. DECLARE @VAR1 varchar SET
I have a simple problem that I have not been able to find an
I have a simple problem while putting text in multiple table! please have a
I have a simple problem that I've been stuck on for some time and

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.