2

With this xml:

    <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" />

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

        <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:background="@drawable/greyframe"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="25" />
    </LinearLayout>

...the EditTexts do not even display. Why? This is a followup to my question here, which has grown so long that I can no longer add to it.

UPDATE

Okay, this looks purdy darn purdy ("...HUH?!? I think I look kinda purdy, don't you?!?" <= guess that flick):

<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="match_parent"
            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" />

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

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

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="7"
                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="34"
                android:background="@drawable/greyframe" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="23"
                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="34"
                android:background="@drawable/greyframe" />
        </LinearLayout>

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

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

            <EditText
                android:id="@+id/editTextDesc"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="8"
                android:background="@drawable/greyframe" />

        </LinearLayout>

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

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

            <EditText
                android:id="@+id/editTextQty"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:background="@drawable/orangeframe" />

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

            <EditText
                android:id="@+id/editTextCount"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:background="@drawable/greyframe"
                android:editable="false" />
        </LinearLayout>

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

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

            <EditText
                android:id="@+id/editCost"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/orangeframe" />

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

            <EditText
                android:id="@+id/editTextMargin"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/orangeframe" />

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

            <EditText
                android:id="@+id/editList"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/orangeframe" />
        </LinearLayout>

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

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

            <Spinner
                android:id="@+id/spinnerDept"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="@drawable/greyframe"
                android:entries="@array/departments" />

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

            <EditText
                android:id="@+id/editTextDollar"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="@drawable/greyframe" />

        </LinearLayout>

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

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

            <Spinner
                android:id="@+id/spinnerSubdept"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:background="@drawable/greyframe"
                android:entries="@array/subdepartments" />
        </LinearLayout>

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

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

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

                <EditText
                    android:id="@+id/editTextDelivInvNum"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/greyframe"
                    android:editable="false" />

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

                <EditText
                    android:id="@+id/editTextVendor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/greyframe"
                    android:editable="false" />
            </LinearLayout>

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

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

                <EditText
                    android:id="@+id/editTextTotalDollars"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/greyframe" />

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

                <EditText
                    android:id="@+id/editTextCurrentTotal"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/greyframe" />

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

                <EditText
                    android:id="@+id/editTextReadonlyQty"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/greyframe" />
            </LinearLayout>
        </LinearLayout>

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

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

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

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

    </LinearLayout>
</ScrollView>

UPDATE 2

This is how that layout looks at design-time in Droidio:

enter image description here

It's not Yosemite, but neither is it Tonopah, Nevada.

UPDATE 3

Based on what I read here, I changed the "dp"s to "dip"s.

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • I demonstrate you that no, it isn't so. Just that I used **1** for weights instead of **25**, for shortness (1 char saved for 4 Views = 4 chars saved). Multiply it for 10 rows, 40 chars saved, which is 80 bytes in UTF-8. Small optimizations... – Phantômaxx May 28 '14 at 17:13
  • 1
    Well, B. Clay. We are at it, again. The concept simplified in your question extends to **each of the rows** in your update. – Phantômaxx May 28 '14 at 18:33
  • 1
    I only see `wrap_content` in both width and height of your children Views. Whereas I should see the width="0dp", height="wrap_content" and weight="1". **FOR ALL children Views in all rows**. – Phantômaxx May 28 '14 at 18:35
  • What do you mean - is there something right with my update? It seems to work fine... – B. Clay Shannon-B. Crow Raven May 28 '14 at 18:35
  • By "children views" do you mean LinearLayouts, or all the elements (Spinner, EditText, &c)? – B. Clay Shannon-B. Crow Raven May 28 '14 at 18:36
  • I'd also get rid of the minWidth(s) in your EditTexts (a refuse of the past design, I suppose). – Phantômaxx May 28 '14 at 18:36
  • The children Views (EditTexts, Spinners, ...) – Phantômaxx May 28 '14 at 18:37
  • Okay, I updated (overwrote) the Update; the weights still need some tweaking, but I think it's pretty close to perfect. Well, good enough. – B. Clay Shannon-B. Crow Raven May 28 '14 at 18:58
  • Row 1 weights: 7 + 23 + 34 +34 = 98. Row 2: again LinearLayouts **RUINING the weight sum**!! Row 3: **NO WEIGHTS AT ALL**. Row 4-9: See Row 3. – Phantômaxx May 28 '14 at 19:04
  • It's late, here (21:06)... Gonna come back in 12 hrs. – Phantômaxx May 28 '14 at 19:06
  • I made Row 1 == 100, but 98 was working just as well, if not better; Row 2 is just fine as-is. You must have been looking at an old version of the update, because everything has weights now. Schlaf gut. – B. Clay Shannon-B. Crow Raven May 28 '14 at 19:19
  • Now, we finally made it work. Very good. Don't understand "purdy" (my English vocabulary is limited, not being a motherlanguager - sometimes I also create new words, maybe). Danke sehr (Thanks a lot). Du auch (You too). – Phantômaxx May 29 '14 at 07:39
  • Ja, ich spreche Deutsch und verstehe alles; "purdy" is a lowbrow way of saying "pretty" sometimes to humorous effect, such as in the case quoted above, from the movie "Holes" (Jon Voigt's character says it). – B. Clay Shannon-B. Crow Raven May 29 '14 at 15:09
  • I see: **purdy**. Today I learned something new. I must re-learn German, since I want to move to Germany and start my own company (here in Italy life is getting harder and harder: companies close at a rate of 2 per hour, and suicides increase). – Phantômaxx May 29 '14 at 15:12
  • Email me at my full name here as one word (initial+middlename+lastname) "bei" att dot com, and I'll let you know a trick I use in learning languages. I learned German half my life ago this way, and am currently learning Spanish. It's still a lot of work, a huge investment of time, but I find it effective. Well, first of all, I would say: try Duolingo (see https://www.duolingo.com/B.ClayShan)! But that's not all of it. – B. Clay Shannon-B. Crow Raven May 29 '14 at 15:31

3 Answers3

2

I believe the layout width of your LinearLayout container must be definite for weight to recalculate width of child containers. Try changing its width from "wrap_content" to "fill_parent".

BrettAM
  • 121
  • 1
  • 3
0

The width of your views is set to 0dp. Try changing those to "match_parent".

bstar55
  • 3,542
  • 3
  • 20
  • 24
  • `The width of your views is set to 0dp.` or weights won't work at all. `Try changing those to "match_parent".` completely wrong: only the container must fill the available space. – Phantômaxx May 29 '14 at 10:41
0

Here I demonstrate you that no, it isn't so.
Just that I used 1 for weights instead of 25, for shortness (1 char saved for 4 Views = 4 chars saved).
Multiply it for 10 rows, 40 chars saved, which is 80 bytes in UTF-8.
Small optimizations...

Try this, B. Clay:

<?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="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp"
    >
    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/id"
        android:textAppearance="?android:attr/textAppearanceMedium"
    />
    <EditText
        android:id="@+id/editTextID"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
    />
    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        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="1"
    />
</LinearLayout>

I got this result:

enter image description here

I just removed the android:background="@drawable/greyframe", since I haven't got that resource.
Note that the trial has been done on an emulated 2.8" ldpi (240*320) screen.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115