2

使用此 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>

... EditTexts 甚至不显示。为什么?这是我的问题here的后续,它已经增长了很长时间,以至于我无法再添加它。

更新

好吧,这看起来很糟糕(“......嗯?!?我觉得我看起来有点糟糕,不是吗?!?” <=猜那个电影):

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

更新 2

这是该布局在 Droidio 中的设计时外观:

在此处输入图像描述

它不是优胜美地,但也不是内华达州托诺帕。

更新 3

根据我在这里阅读的内容,我将“dp”更改为“dip”。

4

3 回答 3

2

我相信您的 LinearLayout 容器的布局宽度必须确定权重才能重新计算子容器的宽度。尝试将其宽度从“wrap_content”更改为“fill_parent”。

于 2014-05-28T17:01:01.287 回答
0

视图的宽度设置为 0dp。尝试将它们更改为“match_parent”。

于 2014-05-28T17:07:04.193 回答
0

在这里,我向您证明,不,不是这样。
只是我使用1作为权重而不是25,为了简短(为 4 个视图保存 1 个字符 = 保存 4 个字符)。
将其乘以 10 行,保存 40 个字符,即 UTF-8 中的 80 个字节。
小优化...

试试这个,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>

我得到了这个结果:

在此处输入图像描述

我刚刚删除了android:background="@drawable/greyframe",因为我没有那个资源。
请注意,试验是在模拟的 2.8" ldpi (240*320) 屏幕上完成的。

于 2014-05-28T17:09:28.983 回答