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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:11:58+00:00 2026-06-11T21:11:58+00:00

I have a layout whose root ViewGroup has two children only one of which

  • 0

I have a layout whose root ViewGroup has two children only one of which is always visible. The other child’s visibility will be set at runtime to View.GONE when not applicable.

When both children are visible, the heights are set to wrap_content and the layout looks great. The problem is that I’d like to expand the visible view to match_parent when the other is gone.

Is there any way to accomplish this or the equivalent?

  • 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-11T21:11:59+00:00Added an answer on June 11, 2026 at 9:11 pm

    You can change any View’s layout like this:

    view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    

    The constructor takes width then height as in: new LayoutParams(int width, int height).
    Also there is a LayoutParams class for each type of ViewGroup. Make sure you import the one that refers your particular ViewGroup. So if your ViewGroup is a LinearLayout use:

    import android.widget.LinearLayout.LayoutParams;
    

    I tried unsuccessfully figuring this strategy out

    I’m not certain where you had trouble, but this approach only requires a couple extras lines:

    // When you want to show both views
    view1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    view2.setVisibility(View.VISIBLE);
    ...
    
    // When you want to hide the second view
    view1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    view2.setVisibility(View.GONE);
    

    If you hide / show the views multiple times you can save a reference to each LayoutParams object rather than repeatedly creating new objects.

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

Sidebar

Related Questions

I have a layout with two children one after another, like this: |<view1><text1> |
I have an UIViewController that has two UIViews inside, whose layout (set in Interface
I have a Silverlight 3 application the inside of whose grid layout root looks
I have an activity whose layout only contains a VideoView. Here is the xml:
If for example I have defined a root linear layout whose orientation is vertical:
I have a website whose layout has been shown in the diagram. The body
I have a border layout whose center panel is defined like the below. {
I have an unordered list whose list items are displaying inline. However, its layout
I have a layout like this in which I want to display a label
I have a layout which looks like this: <LinearLayout> <ImageView> android:width=wrap_content android:height:wrap_content ... </ImageView>

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.