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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:00:42+00:00 2026-06-09T13:00:42+00:00

I´m writing an Android Aplication that is very similar to a binary tree/graph, there

  • 0

I´m writing an Android Aplication that is very similar to a binary tree/graph, there are several buttons created dinamically but I can´t figure out how to create lines connecting the buttons.

Here´s an image showing what I need to do:

Here is my XML file:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vscroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000" >

    <HorizontalScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/hscroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#888888" >

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/relativescroll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#FFFFFF" >

            <!-- Buttons and lines connecting them -->

        </RelativeLayout>
    </HorizontalScrollView>

</ScrollView>

And here is an example of the activity class:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.relativescroll);
        RelativeLayout.LayoutParams newParams;

        // Botão 1
        Button btn1 = new Button(this); 
        btn1.setId(1);
        btn1.setText("Botão 1");
        newParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT
                );
        newParams.setMargins(0, 0, 20, 50);
        newParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        btn1.setLayoutParams(newParams);
        mainLayout.addView(btn1);

        // Botão 2
        Button btn2 = new Button(this);
        btn2.setId(2);
        btn2.setText("Botão 2");
        newParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT
                );
        newParams.setMargins(0, 0, 20, 50);
        newParams.addRule(RelativeLayout.BELOW, 1);
        newParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        btn2.setLayoutParams(newParams);
        mainLayout.addView(btn2); 

        // Botão 3
        Button btn3 = new Button(this);
        btn3.setId(3);
        btn3.setText("Botão 3");
        newParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT
                );
        newParams.setMargins(0, 0, 20, 50);
        newParams.addRule(RelativeLayout.BELOW, 1);
        newParams.addRule(RelativeLayout.RIGHT_OF, 2);
        btn3.setLayoutParams(newParams);
        mainLayout.addView(btn3);

        // Botão 4
        Button btn4 = new Button(this);
        btn4.setId(4);
        btn4.setText("Botão 4");
        newParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT
                );
        newParams.setMargins(0, 0, 20, 50);
        newParams.addRule(RelativeLayout.BELOW, 1);
        newParams.addRule(RelativeLayout.RIGHT_OF, 3);
        btn4.setLayoutParams(newParams);
        mainLayout.addView(btn4);

        // Botão 4
        Button btn5 = new Button(this);
        btn5.setId(5);
        btn5.setText("Botão 5");
        newParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT
                );
        newParams.setMargins(0, 0, 20, 50);
        newParams.addRule(RelativeLayout.BELOW, 1);
        newParams.addRule(RelativeLayout.RIGHT_OF, 4);
        btn5.setLayoutParams(newParams);
        mainLayout.addView(btn5);   

        // DRAW LINK        
        NodeLink link = new NodeLink(this);
        newParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT
                );
        newParams.addRule(RelativeLayout.BELOW, 1);
        newParams.addRule(RelativeLayout.ABOVE, 2);
        newParams.addRule(RelativeLayout.RIGHT_OF, 1);
        newParams.addRule(RelativeLayout.LEFT_OF, 2);
        mainLayout.addView(link);

    }

}

Please, any ideas on how can I do that?

  • 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-09T13:00:44+00:00Added an answer on June 9, 2026 at 1:00 pm

    You might want to say what NodeLink is doing – custom view class?

    Any case, I’d suggest getting the coordinates of “anchors” on your buttons (top-center points, from your diagram), then creating Paths that link associated buttons’ anchors. Draw/paint these Paths into a Picture, save it as a PictureDrawable, and then you can set that Drawable as the background of your buttons’ parent (the RelativeLayout/mainLayout).

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

Sidebar

Related Questions

I'm writing a very simple Android application that showing various shapes on the main
I'm writing an Android application that I want to be able to send requests
I'm writing an android application that draws directly to the canvas on the onDraw
I am writing an Android alarm application that uses a Service in order to
I am writing an application that will allow an android phone and java application
I'm writing an API on Android that will be used by an existing application,
I am writing an Android application which uses several 3D models. Such a model
I'm writing an android application that maintains a lot of state data...some of it
I'm writing an application that will ship in two versions: Android and PC version.
I am writing an application that needs to be supported on both android phones

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.