Why do my EditTexts not display at all?

。_饼干妹妹 提交于 2019-12-11 03:11:36

问题


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:

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.


回答1:


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:

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.




回答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".




回答3:


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



来源:https://stackoverflow.com/questions/23917609/why-do-my-edittexts-not-display-at-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!