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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:38:06+00:00 2026-05-31T03:38:06+00:00

The code is below but I am having some issues with creating a relative

  • 0

The code is below but I am having some issues with creating a relative layout(which is a child to a linearLayout). I think that i am creating both textviews correctly(setting up both IDs) and setting the layoutparams for each correctly.

However, the first textview isn’t centered and the 2nd textview isn’t being drawn to the screen(it should be below the menuTitle). Please let me know where i am going wrong here. The LinearLayout, RelativeLayout in the code is inside a main RelativeLayout(which is noted in the setContentView line). All my custom classes do is simply override the draw method to draw a white border around the view. I DO NOT change the layout parameters at all in these subclasses.(i noticed some people were having issues doing this).

As a side note – these are going to be create dynamically so thats the reason for the programmatic route instead of XML. Anyway thanks all for the help in advance!

    CustomRelativeLayout subMenuLayout = new CustomRelativeLayout(this);
    subMenuLayout.setBackgroundColor(Color.TRANSPARENT);
    RelativeLayout.LayoutParams subMenuLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.FILL_PARENT);
    subMenuLayoutParams.addRule(RelativeLayout.RIGHT_OF, sideMenu.getId());
    subMenuLayoutParams.setMargins(0, 0, 200, 0);
    subMenuLayout.setLayoutParams(subMenuLayoutParams);

    TextView menuItemTitle = new CustomTextView(this);
    menuItemTitle.setText("All You Can Eat");
    menuItemTitle.setTextSize(30);
    menuItemTitle.setBackgroundColor(Color.TRANSPARENT);
    menuItemTitle.setTextColor(Color.WHITE);
    menuItemTitle.setId(2);

    RelativeLayout.LayoutParams menuItemTitleParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.FILL_PARENT);
    menuItemTitleParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    menuItemTitleParams.setMargins(0, 0, 0, 15);
    menuItemTitle.setLayoutParams(menuItemTitleParams);

    TextView menuItemDesc = new CustomTextView(this);
    menuItemDesc.setText("All you can ribs, chicken, pork and sides you can stomach to eat\nAlso includes dessert!");
    menuItemDesc.setTextSize(15);
    menuItemDesc.setBackgroundColor(Color.TRANSPARENT);
    menuItemDesc.setTextColor(Color.WHITE);
    menuItemDesc.setId(3);

    RelativeLayout.LayoutParams menuItemDescParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.FILL_PARENT);
    menuItemDescParams.addRule(RelativeLayout.BELOW, menuItemTitle.getId());
    menuItemDesc.setLayoutParams(menuItemDescParams);

    subMenuLayout.addView(menuItemTitle);
    subMenuLayout.addView(menuItemDesc);

    RelativeLayout screenLayout = new RelativeLayout(this);
    screenLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    screenLayout.setBackgroundResource(R.drawable.body_bkgd);
    screenLayout.addView(sideMenu);
    screenLayout.addView(subMenuLayout);

    setContentView(screenLayout); 

}
  • 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-31T03:38:07+00:00Added an answer on May 31, 2026 at 3:38 am

    I think you need to envelop your TextViews in a vertically oriented LinearLayout. Add both of your TextViews to a LinearLayout instead of the RelativeLayout, then add the LinearLayout to the RelativeLayout with the position parameters you want. Here’s an example:

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation( LinearLayout.VERTICAL );
    
    TextView menuItemTitle = new CustomTextView(this);
    menuItemTitle.setText("All You Can Eat");
    menuItemTitle.setTextSize(30);
    menuItemTitle.setBackgroundColor(Color.TRANSPARENT);
    menuItemTitle.setTextColor(Color.WHITE);
    
    LinearLayout.LayoutParams menuItemTitleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT);
    menuItemTitleParams.gravity = Gravity.CENTER_HORIZONTAL;
    menuItemTitle.setLayoutParams(menuItemTitleParams);
    
    TextView menuItemDesc = new CustomTextView(this);
    menuItemDesc.setText("All you can ribs, chicken, pork and sides you can stomach to eat\nAlso includes dessert!");
    menuItemDesc.setTextSize(15);
    menuItemDesc.setBackgroundColor(Color.TRANSPARENT);
    menuItemDesc.setTextColor(Color.WHITE);
    menuItemDesc.setLayoutParams(menuItemTitleParams);
    
    linearLayout.addView(menuItemTitle);
    linearLayout.addView(menuItemDesc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn C++ currently, but I'm having issues with the code below.
For the code below, I am having some issues in IE. The second parameter
Ok I am still having some issues with this code below. I have received
I'm having some issues with a regular expression I'm creating. I need a regex
A client is having an issue running java2ws on some of their code, which
I am having some issues with a thrown exception. Below is the draw method
I am trying to run the code below but it keeps locking up my
the code below works fine but it takes an absolute age to run. How
Currently my code below works fine but it's a bit of overkill. In my
How to Remove Badge from the tabbar item i had use below code but

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.