4

Based on how XAML works, I thought I could give my android widgets a percentage value for width. After searching, I found that *theoretically," this is available via the "layout_weight" property. But using this does not produce the desired appearance. Specifically, this xml:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp">

    <Spinner
        android:id="@+id/spinnerUPCPLU"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".40"
        android:entries="@array/delivery_upcplu_spinner" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/greyframe"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/editTextUPCPLU"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".90"
            android:editable="false" />
    </LinearLayout>

</LinearLayout>

...gives me this:

enter image description here

I can brute-force the layout to look more-or-less as I want it using explicit width values, like so:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp">

    <Spinner
        android:id="@+id/spinnerUPCPLU"
        android:layout_width="160dp"
        android:layout_height="40dp"
        android:entries="@array/delivery_upcplu_spinner" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/greyframe"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/editTextUPCPLU"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:editable="false"
            android:minWidth="200dp" />
    </LinearLayout>

</LinearLayout>

...which looks like this:

enter image description here

...but doing this (assigning specific dp vals to the width) makes me more nervous than a cat in a roomful of rocking chairs.

Is there balsam in Gilead? I mean, is there, after all, a way to assign percentage widths (that actually works, of course)?

Am I using layout_weight wrong, or am I using the wrong methodology, or is it (perish the thought) impossible?

UPDATE

The accepted answer worked in one instance, but in the next:

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="@string/id"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editTextID"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="@string/pack_size"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editTextPackSize"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25" />
    </LinearLayout>

...it doesn't:

enter image description here

It takes up half the width instead of all of it; must I put some "replace" talk in the EditText widgets for them to "widen out"?

I can "force it" by adding to the EditTexts:

android:minWidth="120dp"

...but that returns me to the nervosity level of the rocking-chair-room cat.

UPDATE 2

Now even what I thought was working is not, or no longer. The xml is this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="4dp"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hhs.app.DeliveryActivity">

    <!--Row 0-->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp"
        >
        <Spinner
            android:id="@+id/spinnerUPCPLU"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".10"
            android:maxWidth="12dp"
            android:entries="@array/delivery_upcplu_spinner"
            />
        <EditText
            android:id="@+id/editTextUPCPLU"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".90"
            android:minWidth="1200dp"
            android:editable="false"
            />
    </LinearLayout>

    <!--Row 1-->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="@string/id"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/greyframe"
            android:orientation="horizontal">
        <EditText
            android:id="@+id/editTextID"
            android:layout_width="0dp"
            android:minWidth="120dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25" />
        </LinearLayout>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="@string/pack_size"
            android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/greyframe"
                android:orientation="horizontal">
        <EditText
            android:id="@+id/editTextPackSize"
            android:layout_width="0dp"
            android:minWidth="120dp"
            android:layout_height="wrap_content"
            android:layout_weight=".25" />
            </LinearLayout>
    </LinearLayout>

...and it looks like this:

enter image description here

IOW, in the first row, the EditText is getting scrunched like a svelte trainer by an age-old elephant, and in the next row, the attempted equality of widths is not being observed (although it actually looks fine, those labels are not taking one-quarter of the width, but only what they need and no more).

And, the same is the case when I change ".25" to either "0.25" or "1" in all cases.

UPDATE 3

Okay, here is what I see with my LinearLayout with various combinations of "match_parent" and "wrap_content" for its "layout_width" and "layout_height" properties.

When both are set to wrap_content:

enter image description here

When both are set to match_parent:

enter image description here

If width is set to match_parent, and height is set to wrap_content, it is the same as when BOTH are set to match_parent The other way around (with height set to match_parent and width set to wrap_content), it is the same as when BOTH are set to wrap_content

UPDATE 4

Here is the entire contents of this particular layout file, at its best, albeit not perfect by any means:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="4dp"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="hhs.app.DeliveryActivity">

        <!--Row 0-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:padding="5dp"
            >
            <Spinner
                android:id="@+id/spinnerUPCPLU"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight=".10"
                android:maxWidth="12dp"
                android:entries="@array/delivery_upcplu_spinner"
                />
            <EditText
                android:id="@+id/editTextUPCPLU"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight=".90"
                android:minWidth="1200dp"
                android:editable="false"
                />
        </LinearLayout>

        <!--Row 1-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="25"
                android:text="@string/id"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/greyframe"
                android:orientation="horizontal">
            <EditText
                android:id="@+id/editTextID"
                android:layout_width="0dp"
                android:minWidth="120dp"
                android:layout_height="wrap_content"
                android:layout_weight="25" />
            </LinearLayout>

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="25"
                android:text="@string/pack_size"
                android:textAppearance="?android:attr/textAppearanceMedium" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/greyframe"
                    android:orientation="horizontal">
            <EditText
                android:id="@+id/editTextPackSize"
                android:layout_width="0dp"
                android:minWidth="120dp"
                android:layout_height="wrap_content"
                android:layout_weight="25" />
                </LinearLayout>
        </LinearLayout>

        <!--Row 2-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/desc"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/greyframe"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editTextDesc"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="320dp" />
            </LinearLayout>

        </LinearLayout>

        <!--Row 3-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/qty"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/orangeframe"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editTextQty"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="144dp" />
            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/count"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/greyframe"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editTextCount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:editable="false"
                    android:minWidth="144dp" />
            </LinearLayout>

        </LinearLayout>

        <!--Row 4-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/cost"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/orangeframe"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editCost"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="48dp" />
            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/margin"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/orangeframe"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editTextMargin"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="48dp" />
            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/list"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/orangeframe"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editList"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="48dp" />
            </LinearLayout>

        </LinearLayout>

        <!--Row 5-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/dept"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/greyframe"
                android:orientation="horizontal">

                <Spinner
                    android:id="@+id/spinnerDept"
                    android:layout_width="180dp"
                    android:layout_height="40dp"
                    android:entries="@array/departments" />
            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="$"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/greyframe"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/editTextDollar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="48dp" />
            </LinearLayout>

        </LinearLayout>

        <!--Row 6-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/sub_dept"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/greyframe"
                android:orientation="horizontal">

                <Spinner
                    android:id="@+id/spinnerSubdept"
                    android:layout_width="248dp"
                    android:layout_height="40dp"
                    android:entries="@array/subdepartments" />
            </LinearLayout>

        </LinearLayout>

        <!--Row 7-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/box"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/delivery_invoice_number"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/greyframe"
                    android:orientation="horizontal">

                    <EditText
                        android:id="@+id/editTextDelivInvNum"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:editable="false"
                        android:minWidth="124dp" />
                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/vendor"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/greyframe"
                    android:orientation="horizontal">

                    <EditText
                        android:id="@+id/editTextVendor"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:editable="false"
                        android:minWidth="124dp" />
                </LinearLayout>

            </LinearLayout>

            <!--Row 8-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="5dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/total_dollars"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/greyframe"
                    android:orientation="horizontal">

                    <EditText
                        android:id="@+id/editTextTotalDollars"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minWidth="80dp" />
                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/current_total"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/greyframe"
                    android:orientation="horizontal">

                    <EditText
                        android:id="@+id/editTextCurrentTotal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minWidth="80dp" />
                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/qty"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/greyframe"
                    android:orientation="horizontal">

                    <EditText
                        android:id="@+id/editTextReadonlyQty"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minWidth="40dp" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <!--Row 9-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp">

            <Button
                android:id="@+id/buttonSave"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/save" />

            <Button
                android:id="@+id/buttonFind"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/find" />

            <Button
                android:id="@+id/buttonClear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/clear" />
        </LinearLayout>

    </LinearLayout>
</ScrollView>

UPDATE 5

Okay, what I'm getting out of this is that the internal-most LinearLayouts need to be thus:

android:layout_width="match_parent"
android:layout_height="wrap_content"

...and all others (above them) thus:

android:layout_width="wrap_content"
android:layout_height="wrap_content"

That works for the most part. But the EditTexts are too puny. If I remove the inner LinearLayouts completely, the EditTexts disappear (or have dimensions of 0?)

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    Please, B. Clay! Remove the LinearLayouts surrounding your EditTexts... You don't want them: they break your weights. – Phantômaxx May 27 '14 at 18:45
  • But that's how I can add the drawable backgrounds. – B. Clay Shannon-B. Crow Raven May 27 '14 at 19:11
  • 1
    No, you can set `android:background="@drawable/greyframe"` directly to your EditTextsvor to the Container LinearLayout (the one that includes the TextView too). Otherwise, you will loose the **weight** functionality. Which appears to be a requisite. – Phantômaxx May 27 '14 at 19:16
  • 1
    No!! :) (I understood what you're doing) THE `CONTAINER` must take **match_parent** as its width. BOTH `CHILDREN` have to be **0dp** wide, to make their weight work – Phantômaxx May 27 '14 at 19:24
  • 1
    I hope all your doubts now vanished, so you can put your post on CodeProject. ;) – Phantômaxx May 27 '14 at 19:31
  • Well, I still have my doubts about the merits of Lady Gaga's "music," among other things. – B. Clay Shannon-B. Crow Raven May 27 '14 at 20:30
  • The last example shown *is* what it looks like with the container set to "match_parent" and the two widgets indeed having a width of 0 dp. In the interests of "full disclosure," I am adding the entire Layout file contents to Update 4. – B. Clay Shannon-B. Crow Raven May 27 '14 at 20:34
  • 1
    No... In update 4 I still see **a bunch of errors**. On row, randomly: the ROW CONTAINER LinearLayout has this attribute `android:layout_width="wrap_content"` instead of `android:layout_width="match_parent"`, while the hight is the opposite - should be vice-versa (height=wrap and width=match); Row1: same issue with width, but the height is correct; AND the EditTexts are **ERRONEOUSLY ENCLOSED IN ANOTHER LinearLayout - THIS WILL NEVER WORK**; **Row2 to 8: PLEASE REMOVE THE EXTRA LAYUTS AROUND VIEWS**. Row9 suffers from the "wrap_content syndrome" (and there's no weight applied). – Phantômaxx May 28 '14 at 07:35
  • 1
    I suspect that minWidth is also to be removed, for weights to work. When you remove the LinearLayouts suttounding the EditTexts and Spinners, you also have to re set the weights to a proper value and the widths to 0dp – Phantômaxx May 28 '14 at 16:37
  • Removing the inner LinearLayouts invisiblizes the EditTexts; I added a new question here: http://stackoverflow.com/questions/23917609/why-do-my-edittexts-not-display-at-all – B. Clay Shannon-B. Crow Raven May 28 '14 at 16:56

2 Answers2

3

You should have a single LinearLayout containing all the "weighted" widgets.
Note that only 1 dimension at a time can be "weighted":

This is how I'd do that:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="8dp"
    >
    <Spinner
        android:id="@+id/spinnerUPCPLU"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".40"
        android:entries="@array/delivery_upcplu_spinner"
    />
    <EditText
        android:id="@+id/editTextUPCPLU"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".60"
        android:editable="false"
    />
</LinearLayout>

Note that the weight sum is 1 (android calculates it by itself).
I could set 4 and 6 or 40 and 60 - for Android that's always 100%, when summed.

You can optionally set a weightSum attribute in the Containing LinearLayout:

android:weightSum="1"

(or 10, or 100, ...)

If you want to (and your layout isn't complex), you can weight the other "dimension" (height in this case), too.

Just add another LinearLayout containing another Spinner and EditText.

Then enclose these 2 LinearLayouts in a third one.

Give both the children LinearLayouts a weight of 1 and a height of 0dp, so they will equally divide the container's height.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Please see my followup (Update) – B. Clay Shannon-B. Crow Raven May 27 '14 at 17:10
  • Yes... OK, just try using **1** instead of **0.25**. Android will fix the weightSum to **4** (and will autoMAGICALLY interpret **1 as 25%** and **4 as 100%**). By the way, why do you use an EditText, if you make it uneditable? as per `android:editable="false"` Better use a lighter TextView, then... do you agree? – Phantômaxx May 27 '14 at 17:13
  • 1
    `I can "force it"` - please, don't. Forcings are **evil**. And a nervous cat, too. – Phantômaxx May 27 '14 at 17:19
  • I'm addding a grey border around read-only EditTexts (and an orange border around regular/editable ones). – B. Clay Shannon-B. Crow Raven May 27 '14 at 17:46
  • OK, I saw **something weird**: `android:layout_width="wrap_content"` it should read: `android:layout_width="match_parent"`, since you want to **fill the parent's width** and subdivide it equally... – Phantômaxx May 27 '14 at 18:24
  • Should layout_width be set to match_parent in every case (never be wrap_content)? – B. Clay Shannon-B. Crow Raven May 27 '14 at 19:12
  • `wrap_content` is like saying "just the space my children (or I myself) need". `match_parent` says: "gimme all the available (remaining) space". It's a **BIG difference**. Well, at least, it's **notable**. – Phantômaxx May 27 '14 at 19:19
1

Some thing like that:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="8dp"
    >
    <Spinner
        android:id="@+id/spinnerUPCPLU"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="50"
        android:entries="@array/delivery_upcplu_spinner"
    />
    <EditText
        android:id="@+id/editTextUPCPLU"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="50"
        android:editable="false"
    />
</LinearLayout>

or

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="8dp"
    >
    <Spinner
        android:id="@+id/spinnerUPCPLU"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="70"
        android:entries="@array/delivery_upcplu_spinner"
    />
    <EditText
        android:id="@+id/editTextUPCPLU"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="30"
        android:editable="false"
    />
</LinearLayout>
Igor Tyulkanov
  • 5,487
  • 2
  • 32
  • 49