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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:23:22+00:00 2026-05-23T09:23:22+00:00

In Android, I need to be able to draw simple graphics (points, lines, circles,

  • 0

In Android, I need to be able to draw simple graphics (points, lines, circles, text) on a large scrollable canvas (i.e the phone’s screen is a viewport in a much larger area). I have hunted for tutorials on how to do this without success.

“World Map FREE” on Android market is a good example of the sort of effect I need to achieve.

This must be a common problem, so I’m surprised I can’t find examples.

  • 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-23T09:23:23+00:00Added an answer on May 23, 2026 at 9:23 am

    I’ve had to implement something fairly recently of this sort. Basically I had coordinates in my custom view that would shift where objects would be drawn, via some auxiliarry functions:

    public class BoardView extends View {
    
        //coordinates to shift the view by
        public float shiftX=0f;
        public float shiftY=0f;
    
        //used in the dragging code
        public float lastX=-1f;
        public float lastY=-1f;
    
        /*...*/
    
        //functions that take into account the shifted x and y values
        //pretty straightforward
        final public void drawLine(Canvas c,float x1,float y1,float x2,float y2,Paint p){
            c.drawLine(x1+shiftX, y1+shiftY, x2+shiftX, y2+shiftY, p);
        }
    
        final public void drawText(Canvas c,String s,int x,int y,Paint p){
            c.drawText(s, x+shiftX, y+shiftY, p);
        }
    
        /*etc*/
    

    To actually implement the dragging, I wrote a custom onTouchEvent method to implement dragging:

    public boolean onTouchEvent(MotionEvent event){
            int eventaction=event.getAction();
            float x=event.getX();
            float y=event.getY();
            switch(eventaction){
            case MotionEvent.ACTION_DOWN:
                time=System.currentTimeMillis();//used in the ACTION_UP case
                break;
            case MotionEvent.ACTION_MOVE:
                if(lastX==-1){ lastX=x;lastY=y;}//initializing X, Y movement
                else{//moving by the delta
                    if(Math.abs(x-lastX)>1 || Math.abs(y-lastY)>1){//this prevents jittery movement I experienced
                        shiftX+=(x-lastX);//moves the shifting variables
                        shiftY+=(y-lastY);//in the direction of the finger movement
                        lastX=x;//used to calculate the movement delta
                        lastY=y;
                        invalidate();//DON'T FORGET TO CALL THIS! this redraws the view
                    }
                }
                break;
            case MotionEvent.ACTION_UP: //this segment is to see whether a press is a selection click(quick press)
            //or a drag(long press)
                lastX=-1;
                if(System.currentTimeMillis()-time)<100)
                    try {
                        onClickEvent(x,y);//custom function to deal with selections
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                break;
            }
            return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need an Android application which should be able to fetch data from the
I am new to writing Android Applications, and I need to be able to
My Android app need the user to create an account to be able to
I'm building an Android App where users need to be able to edit their
I need to be able to programatically add a google account in android for
I'm developing a phonegap app for android and I need to be able to
In one of my Android Application I need to keep the title bar same
[Android Newbie alert] I need to capture the contents of a WebView in a
i need to parse this php xml response in android: <?phpxml version=1.0 encoding=utf-8?> <SmsResponse>
I need to add a shake feature that will refresh my Android application. All

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.