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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:20:34+00:00 2026-06-04T10:20:34+00:00

I have a linear layout with two listviews and two dead buttons. How to

  • 0

I have a linear layout with two listviews and two dead buttons. How to divide the space equally between the list views. I got some suggestions like setting the height to 0dip but it didn’t work. The graphical layout in eclipse shows a correct layout but when I add different number of elements to the lists they expand to different height. Here is the xml.

<?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:orientation="vertical" 
    android:weightSum="2">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:text="Installed engines" >
    </Button>

    <ListView
        android:id="@+id/primary"
        android:layout_width="match_parent"
        android:layout_height="0dp" 
        android:layout_weight="1" >
    </ListView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:text="Active engines" >
    </Button>

    <ListView
        android:id="@+id/secondary"
        android:layout_width="match_parent"
        android:layout_height="0dp" 
        android:layout_weight="1" >
    </ListView>

</LinearLayout>

thanks

Since no one believes me here is an image of what I am getting.
Just the links since I don’t have enough reputation to post pics 🙁
! run
! eclipse

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

After all this may not be xml issue based on this answer Linear Layout and weight in Android

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This is correct for static XML layouts. If you’re adding Views dynamically at runtime, you’ll need to use addView with layout parameters like addView(button, new LinearLayout.LayoutParams(0, height, 1)); This is true even if you’re inflating layouts with the correct width and weight values. – Nuthatch Sep 3 ’11 at 21:41

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I do use the layout inflater to add my view to a tab. Maybe that is the problem ..
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Here is sample code that reproduces the problem when I use an inflator.

public class TestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ParticipantsPanel p = new ParticipantsPanel(this);
        setContentView(p);
    }
}

class ParticipantsPanel extends LinearLayout {
    public ParticipantsPanel(Context ctx) {
        super(ctx);

        LayoutInflater li = LayoutInflater.from(ctx);
        View myView = li.inflate(R.layout.participants, null);
        final ListView primary = (ListView) myView.findViewById(R.id.primary);
        final ListView secondary = (ListView) myView.findViewById(R.id.secondary);
        final ArrayAdapter<String> primaryA = 
            new ArrayAdapter<String>(ctx,R.layout.lvtext);
        final ArrayAdapter<String> secondaryA = 
            new ArrayAdapter<String>(ctx,R.layout.lvtext);

        primaryA.add("hello1");
        primaryA.add("hello2");
        primaryA.add("hello3");
        primaryA.add("hello4");
        primaryA.add("hello5");
        primaryA.add("hello6");
        primaryA.add("hello7");
        primaryA.add("hello8");

        secondaryA.add("select1");
        secondaryA.add("select2");

        primary.setAdapter(primaryA);
        secondary.setAdapter(secondaryA);

        addView(myView);
    }
}

xxxxxxxxxxxxxxxxxxxxxxx

Yet another update.
I think the problem is as Nuthatch ( the guy I referred to from an old post) pointed out : addView() just messes up whatever layout you have in static xml, which is a valuable lesson imo. When I move the code in the ParticipantsPanel to the main activity, and set the view directly without out adding it to another linearlayout, it works as expected. I appreciate an explanation as to why that is the case, and how I may still put my code in a class and have desired behavior.

  • 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-04T10:20:35+00:00Added an answer on June 4, 2026 at 10:20 am

    That code you posted is not a good example. The problem of the two ListViews that don’t take equal space when you use the LayoutInflater is because you inflate the layout file without supplying a parent ViewGroup from which to take its LayoutParams.

    If you use:

    addView(myView, new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT));
    

    or modify the R.layout.participants and replace the parent LinearLayout with a merge tag and also setting:

            this.setOrientation(LinearLayout.VERTICAL);
            this.setWeightSum(2.0f);
            li.inflate(R.layout.participants, this, true);
    

    for the ParticipantsPanel,

    then all should be alright.

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

Sidebar

Related Questions

i have two horizontal scroll views each containing a linear layout item under it.
I have a vertical linear layout with two ListViews. I want the top ListView
I have a linear layout with several buttons in it. The button images are
i need to implement this layout in android..the view must be have two list
I have a custom list view which contains two text views and on button.
I have a linear layout with two textView. First textView has weight 40 and
I have a linear layout with this form <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical
I have a clickable linear layout that I've generated programmaticly, and I want it
So I have a custom ListView object. The list items have two textviews stacked
fI have created two layout files. First one is main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout

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.