android - 是什么导致我的 Android EditText 消失

标签 android android-layout

在过去的一个小时里,我一直在尝试创建我认为相对简单的布局。

我想要的是让一个编辑文本占据我的按钮和标签放在屏幕上后留下的垂直空间。我在 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/

相关文章:

android - 如何在工具栏下方添加 View ?

android - Firebase Analytics 控制台仪表板中的内部错误

java - Android 无法创建 EC KeyPair

android - 在 android 平板电脑中使用 WPA Security 以编程方式设置 wifi

android:<include> 标签导致错误

android - 我想使布局边框如下图所示

Android 对话框 Activity 取出整个屏幕而不是对话框

android - 如何获取 FM 音频流录制的音频源?

android - 模态 Bottom Sheet 在全屏 Activity 中显示导航栏

java - 使用BitmapFactory解码ico格式