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

The Archive Base Latest Questions

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

I’m trying to build a part of a Android View Programmatically, but unfortunately I’m

  • 0

I’m trying to build a part of a Android View Programmatically, but unfortunately I’m having some problems with the RelativeLayout. it makes my Elements overlay on eachother

This is my Code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.insertnew_layout);
    LinearLayout ll =  (LinearLayout) findViewById(R.id.container); 

    ll.setOrientation(LinearLayout.VERTICAL);
    TableLayout tl = new TableLayout(this);
    tl.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


        // fill content
        for (int i = 0; i < 3; i++) {   

        TableRow tr = new TableRow(this);
        tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        RelativeLayout rl = new RelativeLayout(this);
        rl.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        TextView score = new TextView(this);
        score.setText(""+i);
        RelativeLayout.LayoutParams lpScore = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
        lpScore.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        score.setLayoutParams(lpScore);

        TextView description = new TextView(this);
        description.setText("this is my description");
        RelativeLayout.LayoutParams lpDescription = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
        lpDescription.addRule(RelativeLayout.RIGHT_OF, score.getId());

        description.setLayoutParams(lpDescription);

        CheckBox checkbox = new CheckBox(this);
        RelativeLayout.LayoutParams lpCheckbox = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
        lpCheckbox.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        checkbox.setLayoutParams(lpCheckbox);

        rl.addView(score);
        rl.addView(description);
        rl.addView(checkbox);
        tl.addView(rl);

    }

    ll.addView(tl);

This is what it looks like:

output in javacode

As you can see, the “description” is on top of of the “score”.

Here is the same code in xml:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tableLayoutTextEntry" >

<TableRow
    android:id="@+id/tableRowTextEntry"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/score"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="score" />

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/score"
            android:text="description" />

        <CheckBox
            android:id="@+id/checkBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="select" />

    </RelativeLayout>

</TableRow>

</TableLayout>

And here is what it looks like in xml:

output in xml

As you can see, in xml, the toRightOf-command works as expected – the description is to the right of the score

How is that possible? Shouldnt the line

lpDescription.addRule(RelativeLayout.RIGHT_OF, score.getId());

do the same thing?

  • 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-31T02:53:38+00:00Added an answer on May 31, 2026 at 2:53 am

    At the moment you are calling it, score.getId() will return -1 (invalid), because it has not been added yet to the screen with the whole layout processed.
    You will have to set the id manually with setId() before calling getId() and it should all work fine.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.