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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:56:54+00:00 2026-05-30T01:56:54+00:00

At first my programm looks like this: But when i am moving the picture

  • 0

At first my programm looks like this:

enter image description here

But when i am moving the picture around the screen programm turns to:

enter image description here

Red graph is random-generated in onDraw method. So i want to draging picture around and have static background that not inavalidates while im moving picture.

here is my code:
Custom View:
package com.graph.base;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
import java.util.Random;

public class CustomView extends View
{
Random random=new Random();
public CustomView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public CustomView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomView(Context context) {
    super(context);
}
public void onDraw (Canvas canvas)
{
    super.onDraw(canvas);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);
    canvas.drawPaint(paint);
    Path path=new Path();
    path.moveTo(10, 10);
    for (float i=0.5f; i<=140; i+=10)
    {
        path.quadTo(10+i*5, 10+random.nextInt(500), 10+(i+10)*5,     10+random.nextInt(500));
    }
    paint.setDither(true);
    paint.setColor(Color.RED);
    paint.setStyle(Paint.Style.STROKE);    
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(2);
    canvas.drawPath(path, paint);
}

}

MainActivity

package com.graph.base;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class MainActivity extends Activity {
FrameLayout frame;
ImageView image;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    frame=(FrameLayout)findViewById(R.id.frameLayout1);
    image=(ImageView)findViewById(R.id.imageView1);
    image.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            Log.e("TAG", "Touch happend");
            switch (event.getAction())
            {
            case MotionEvent.ACTION_MOVE:
            {
                image.setPadding((int)event.getX(),     (int)event.getY(), 0, 0);
                break;
            }

            }

            return true;
        }
    });
}

public void invalidateButton_Click (View v)
{
    frame.invalidate();
}
}
  • 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-30T01:56:55+00:00Added an answer on May 30, 2026 at 1:56 am

    You’re drawing random lines onto your canvas. This code is called each time the screen is invalidated. If you want to keep the drawing from changing, then set a bitmap into a canvas and draw into the bitmap. In your onDraw() method you’ll then draw the bitmap onto the canvas.

    // Outside of onDraw()
    Bitmap bmDest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas mycanvas = new Canvas(bmDest);
    // Do your drawing on the canvas outside of the onDraw() method
    

    In onDraw(), you’ll simply do this:

    canvas.drawBitmap(bmDest, x, y, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two singletons, the first one's header looks like this (I've omitted everything
I am running a bit of code that looks like this: result = system(ruby
I have a .plist file that looks like this: <plist version=1.0> <array> <dict> <key>name</key>
I'm running a scheduling algorithm with a garbage collection snippet that looks like this:
I have a Python program for Linux almost looks like this one : import
I have a piece of code that looks like this: Algorithm a = null;
Let's say I have a function that looks like this: public void saveBooking(/* some
In my program I have currently a piece of code that looks like this
I don't understand why the first program in JSP is working, but the second
Okay. I have completed my first python program.It has around 1000 lines of code.

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.