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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:52:12+00:00 2026-06-05T12:52:12+00:00

I just started programming in android and I want to draw a line that

  • 0

I just started programming in android and I want to draw a line that connects buttons that I click on. I have a gridLayout with a lot of buttons that are defined in the main XML file. I would like to have a straight line drawn from the center of the first clicked button to the next button I push, and so on (sometimes ending at the first button I clicked, so it makes some shape). I have done a lot of research on canvases, animations but can’t figure out where to start. Any help would be greatly appreciated – thanks.

RG

P.S. I would eventually like to animate the connecting lines, but first things first.

  • 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-05T12:52:14+00:00Added an answer on June 5, 2026 at 12:52 pm

    The best way to do the drawing would be to override the draw-method of your GridLayout. Notably not the onDraw method, since that one gets called before your child views are drawn and would thus put your lines into the background. Remember to call the super method before doing your drawing.

    After the first layout pass (i.e. after onLayout has been called at least once) the positions of your buttons should be initialized. You can get their relative positions to their parent by calling getLeft, getTop etc. on them. You can use that to calculate their center coordinates.

    You will have to tell your GridLayout somehow on which buttons to draw the lines. Easiest way would probably be to give each button an OnClickListener, and tell their parent (getParent) that it was clicked and should thus start drawing lines accordingly, for example by building up a set of line objects with the coordinates of the clicked buttons. To force a redraw of the GridLayout after each click you can call invalidate on it.

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

Sidebar

Related Questions

I have just recently started out programming for Android, and have decided that I
I'm just getting started with android programming, and want to see if there is
i have just started android programming, wrote a quick code, and havn't managed to
i have just started programming for android and i have a little question i
I have just started programming on iOS a couple of weeks ago, so sorry
I have just started programming and have made a few small applications in C
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied
I have just started programming in C++ and I was playing around with templates.
I've just recently started programming for the iPhone and I'm making an application that
I just started programming for Android when my boss asked me to make him

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.