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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:00:55+00:00 2026-06-12T00:00:55+00:00

I have a LinearLayout oriented vertically, and I’m trying to add three sub-views to

  • 0

I have a LinearLayout oriented vertically, and I’m trying to add three sub-views to it. One view is a small, 50px high view that just draws a box in it, the second view is a horizontal list of radio buttons, and the third view is a graph.

If I add the graph last, everything fits on screen, but if I add the graph first, it pushes everything off screen and it becomes the only view on the screen. The graph is a custom control of mine that wants to be as big as it can (its onMeasure function just returns the provided width and height), which I think is where the problem lies. But I want to keep it as big as possible, and have the layout fit the views regardless of their order added.

Is this possible? If so, how can I accomplish it? Ultimately, I’m trying to put the graph on top and the other two controls below it, but if I add the graph first it consumes the whole screen.

Here’s the code I’m using to create the views. This is a school assignment and I can’t use XML layouts for it. I’ve been assigned to make a control, which I’ve completed. I’m just trying to make a simple activity to show the control off.

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);

        layout.addView(new MovingBox(this));

        RadioGroup radioGroup = new RadioGroup(this);
        radioGroup.setOrientation(RadioGroup.HORIZONTAL);
        radioGroup.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

        RadioButton button = new RadioButton(this);
        button.setText("Light");
        button.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.WRAP_CONTENT, 1));
        radioGroup.addView(button);

        button = new RadioButton(this);
        button.setText("Dark");
        button.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.WRAP_CONTENT, 1));
        radioGroup.addView(button);

        button = new RadioButton(this);
        button.setText("Colorful");
        button.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.WRAP_CONTENT, 1));
        radioGroup.addView(button);

        layout.addView(radioGroup);

        // If I move these next to lines just below layout.setOrientation(...) it becomes the only thing visible
        TweenerControl tw = new TweenerControl(this);
        layout.addView(tw);

        setContentView(layout);
    }
}

Adding the graph last: (everything fits but I’d like the graph on top)

Adding the graph last

Adding the graph first: (only the graph is visible)

Adding the graph 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-12T00:00:56+00:00Added an answer on June 12, 2026 at 12:00 am

    I’ve worked on this more, and the solution I’ve come up with is to not use LinearLayout and use RelativeLayout instead. RelativeLayout tries to position and size things so they properly fit, whereas LinearLayout just gets the size of things and lays them out in top to bottom order, where items higher in the LinearLayout don’t care about the sizing of items lower in the LinearLayout.

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

Sidebar

Related Questions

I have a LinearLayout in my xml. On runtime i add one image view
I have a LinearLayout view that I am trying to add a divider to
I have one textview with four edittext in linearlayout oriented horizontally.On next linearlayout again
I have a vertically oriented LinearLayout that has a child LinearLayout that includes a
I have a linearlayout in which i have one image view, one textview ,
I have LinearLayout in my xml file that I am trying to add a
I have a LinearLayout view that already contains several elements. I want to add
I have an empty LinearLayout , and I need to add a dynamic number
I have a simple slide action for LinearLayout View using TouchListener . The problem
In app I have: LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.cvLinearLayout2); and after : linearLayout2.setVisibility(View.GONE); I

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.