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

  • Home
  • SEARCH
  • 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 4620890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:37:19+00:00 2026-05-22T02:37:19+00:00

Hi i need to draw a path simple lines to the canvas it should

  • 0

Hi i need to draw a path simple lines to the canvas it should write out red rectangle with white lines.but it do not draw out nothing what m i missing.
my code:

Canvas canvas = new Canvas();


       Paint paint = new Paint();

       paint.setStyle(Paint.Style.FILL);
       paint.setColor(Color.RED);
       canvas.drawPaint(paint);
       Path path = new Path();
       //canvas.drawColor(Color.CYAN);

       for (int i = 5; i < 50; i++) {

           path.moveTo(4, i-1);
           path.lineTo(4, i);

       }
       path.close();

       paint.setStrokeWidth(3);
       paint.setPathEffect(null);
       paint.setColor(Color.WHITE);
       paint.setStyle(Paint.Style.STROKE);

       canvas.drawPath(path, paint);

        for (int i = 0; i < 3; i++) {
            View iview =    inflater.inflate(R.layout.linear_layout, null);
            if(i == 0){
                iview.findViewById(R.id.imageView1).setBackgroundResource(R.drawable.distspeed);
            }
            if(i == 1){
                iview.findViewById(R.id.imageView1).setBackgroundResource(R.drawable.hxmdist);
            }
            if(i == 2){
                iview.findViewById(R.id.imageView1).setBackgroundResource(R.drawable.hxmspeeed);
            }

            iview.draw(canvas);

            realViewSwitcher.addView(iview);
        }
  • 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-22T02:37:20+00:00Added an answer on May 22, 2026 at 2:37 am

    i only post the working code:

    modified activity:

    for (int i = 0; i < 2; i++) {
    
            MyView mView = new MyView(this,i);
    
            realViewSwitcher.addView(mView);
            }
    

    myview:

    public class MyView extends View {
    
        public MyView(Context context, int kolki) {
            super(context);
    
            if (kolki == 0){
                this.setBackgroundResource(R.drawable.distspeed);
            }
            if (kolki == 1){
                this.setBackgroundResource(R.drawable.hxmdist);
            }
        }
    
        public void setBackgroundResource (int resid){
            super.setBackgroundResource(resid);
        } 
    
        public void onDraw(Canvas c){
            super.onDraw(c);
            Paint paint = new Paint();
            Path path = new Path();
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.TRANSPARENT);
            c.drawPaint(paint);
            for (int i = 50; i < 100; i++) {
                   path.moveTo(i, i-1);
                   path.lineTo(i, i);  
            }
            path.close();
            paint.setStrokeWidth(3);
            paint.setPathEffect(null);
            paint.setColor(Color.BLACK);
            paint.setStyle(Paint.Style.STROKE);
            c.drawPath(path, paint);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to draw some simple lines within a Border control (or similar) that
I need to draw text onto a window HDC along a circular path using
I need to draw some simple network topology charts, suggestions of some good tools
I need to draw a graph of write accesses of two concurrently running threads.
In my app, I need to draw a path where every coupe of frames,
I'm drawing images to pdf using Java framework iText. I need to draw lines
I need to draw a curve in WPF on a canvas, which alternates colour,
For my project i need to draw a path between two points on google
I need to draw peak meters for audio in realtime. Minimum 44100 samples per
I need to draw on a TPanel, ideally directly so I don't have another

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.