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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:55:22+00:00 2026-06-05T11:55:22+00:00

Ok, I am completely stuck on this. I have looked everywhere for an answer

  • 0

Ok, I am completely stuck on this. I have looked everywhere for an answer but no solutions I found did me any good. What I am trying to do is add a relative layout to a linear layout and I can do that just fine, the problem is that I can only set the height and the width of the relative layout, and can’t align it below any views in the linear layout. I’m guessing this is because the relative layout isn’t a child of the linear layout? Only reason I am taking the above approach is because I need to add a relative layout for every record I have in a database table. Anyway here is the code below any help would be great 🙂

individual_past_test.xml file

    <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/past_test"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#E4EFF5" >

       <TextView
         android:id="@+id/candidate_name"
         style="@style/past_test_candidate"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:layout_marginLeft="25dp" />

     </RelativeLayout>

IndividualPastTest.java

    public class IndividualPastTests extends RelativeLayout {

    private Context mContext;

    public IndividualPastTests(Context context) {
    super(context);

    mContext = context;

    String infService = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater li;

    li = (LayoutInflater) getContext().getSystemService(infService);
    li.inflate(R.layout.individual_past_test, this, true);
    }
    }

PastTests.java (relevant parts)

    past_tests_label = (TextView) findViewById(R.id.past_tests_label);
    past_tests_label.setId(1);

    addViewForFirstTest();

    private void addViewForFirstTest() {

    past_test = new IndividualPastTests(this);
    RelativeLayout.LayoutParams past_test_view_params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    past_test.setGravity(Gravity.CENTER_HORIZONTAL);

    // Not being called?
    past_test_view_params.addRule(RelativeLayout.BELOW, past_tests_label.getId());

            past_test_view_params.height = 100;
    past_test_view_params.width = 600;


    System.out.println(past_tests_label.getId());

    past_test.setLayoutParams(past_test_view_params);       
    this.addContentView(past_test, past_test_view_params);

}
  • 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-05T11:55:24+00:00Added an answer on June 5, 2026 at 11:55 am

    Ok I ended up fixing it by adding a relative layout to my xml file for past tests(which I didnt add to the question), then changed my PastTests.java as follows –

            // Added this line to get the RelativeLayout I created in the xml to hold my view
            pasts_tests_holder = (RelativeLayout) findViewById(R.id.past_tests_holder)
    
            past_tests_label = (TextView) findViewById(R.id.past_tests_label);
            past_tests_label.setId(1);
    
            addViewForFirstTest();
    
        private void addViewForFirstTest() {
    
            past_test = new IndividualPastTests(this);
            RelativeLayout.LayoutParams past_test_view_params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            past_test.setGravity(Gravity.CENTER_HORIZONTAL);
    
            past_test_view_params.addRule(RelativeLayout.BELOW, past_tests_label.getId());
    
            past_test_view_params.height = 100;
            past_test_view_params.width = 600;
    
            past_test.setLayoutParams(past_test_view_params);       
    
            // Changed this line to add the past_test view to my new relative layout 
            past_tests_holder.addView(past_test);
    

    Here are the relevant parts to my past_tests.xml file for reference –

        <?xml version="1.0" encoding="utf-8"?>
           <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/prev_test_view"
              android:orientation="vertical" >
    
             <RelativeLayout
                 android:id="@+id/past_tests"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_below="@+id/past_tests_label"
                 android:layout_centerHorizontal="true"
                 android:layout_marginTop="227dp" >
    
             </RelativeLayout> 
          </LinearLayout>
    

    Hope this helps anyone else who is having trouble pragmatically setting views in android

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

Sidebar

Related Questions

I almost have this Powershell script completed but I am stuck at the last
So I haven't been doing this for long but I'm completely stuck on this.
I've been trying this for hours, but haven't had any luck. Every tutorial I
I'm trying to build some functionality for a project, but I'm stuck with this:
I'm completely stuck on this error. Using Rails 3.1 trying to implement Formastic Bootstrap
Completely new to most of this stuff, but basically Im playing around with the
Hej folks, I'm currently completely stuck with the following and don't even have the
Ok, so i have got myself completely stuck. My search skill are lacking and
I am completely stuck with this: I start out with a flat file type
I have looked all of the place for this and I can't seem to

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.