在过去的一个小时里,我一直在尝试创建我认为相对简单的布局。
我想要的是让一个编辑文本占据我的按钮和标签放在屏幕上后留下的垂直空间。我在 SO 找到了很多关于如何做到这一点的信息,我觉得我已经在这里实现了这些信息(layout_weight 和 0dip 高度),但是一旦我输入 0dip 高度,我的编辑文本就不会显示。
我在这里错过了什么?
编辑:原来我的 Layout2 被设置为 match_parent,这为加权子项留下了 0 个可用空间。我将那里的行为更改为 wrap_content 并且一切正常。
我的目标是 Android 2.3.3
这是我的布局 xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/description"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:inputType="textMultiLine"
android:layout_weight="1" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clear" />
</LinearLayout>
</LinearLayout>
最佳答案
因为 linearLayout2 填充了父级。 linearLayout2 必须具有 layout_weight 行为或自高度度不匹配父级。
关于android - 是什么导致我的 Android EditText 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9013028/