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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:41:03+00:00 2026-06-17T01:41:03+00:00

Right, this is a strange problem I have been toying with for a while

  • 0

Right, this is a strange problem I have been toying with for a while now, hopefully maybe I am missing something you guys can draw my attention to!

LinearLayouts seem to be disappearing once I add any spacing using views and defining the weight (a method which works elsewhere in the project).

I have a custom Dialog (extends Dialog). In the onCreate() I use the method setContentView(generateDialog()) which returns a vertical LinearLayout.

The LinearLayout has three elements, one row of four custom category buttons (LinearLayouts), one row of sorting buttons (also LinearLayouts) and one ListView which populates the rest of the dialog and refreshes based on which button is pressed.

All is functional and working fine. Except when I attempt to space the buttons out evenly using my spacer method:

Dialog.java:

LinearLayout catBtns = new LinearLayout(context);
        catBtns.setOrientation(LinearLayout.HORIZONTAL);
        catBtns.setBackgroundResource(R.drawable.btn_cat_gradient_bg);
        catBtns.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));

        catBtns.addView(space(1));
        cat1Btn = new CatButton(context,this,act,"CAT1");
        catBtns.addView(cat1Btn);
        catBtns.addView(space(1));
        cat2Btn = new CatButton(context,this,act,"CAT2");
        catBtns.addView(cat2Btn);
        catBtns.addView(space(1));
        cat3Btn= new CatButton(context,this,act,"CAT3");
        catBtns.addView(cat3Btn);
        catBtns.addView(space(1));
        cat4Btn = new CatButton(context,this,act,"CAT4");
        catBtns.addView(cat4Btn);
        catBtns.addView(space(1));

The space() method:

private View space(int space) {
    View view = new View(context);
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(0,0);
    p.weight = space;
    view.setLayoutParams(p);
    return view;
}

What confuses me is that I have been using this method throughout the project and can’t find as to why the category LinearLayout DISAPPEARS COMPLETELY when I add the spacers in between each button.

I use the same technique for the sorting buttons and it works perfectly! I use the same technique in another part of the project using slightly different versions of the same buttons (they are different class files though, because the onClickListener and some other stuff is slightly different)

Anyone have any clue?

  • 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-17T01:41:05+00:00Added an answer on June 17, 2026 at 1:41 am

    I tried to build this in XML and it works fine. A possible difference is, that you do not set any LayoutParams for your buttons. Try something like that for every button:

    cat1Btn = new CatButton(context,this,act,"CAT1");
    catBtns.addView(cat1Btn, new LinearLayout.LayoutParams(0,0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having a strange problem that I've never seen before. Now I have
I have this right now: <%= f.select :credit, (0..500) %> This will result in
I hope I can explain this right I have two input fields that require
I'm facing a strange problem right now... I'm trying to use Facebook API to
I have been confused by a very strange mex error just now . .
I have this strange problem. I have this script: echo $comment_content = $_POST['comment_content']; echo
I am having a strange problem right now with CakePHP. I haven't used the
So I'm having this strange problem. I have a ribbon moving behind the navigation
This is a strange problem. I have two html pop-up windows, just hidden divs
I have a problem and I can't figure out what exactly is causing this

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.