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