EditText 的高度不会扩展到其父级的高度

Eag*_*arn 3 height android parent android-edittext

我使用 height = 在滚动视图中放置了编辑文本match_parent,并期望其高度等于滚动视图,但事实并非如此。它的高度行为就像wrap_content这意味着如果 EditText 中没有文本,我必须将光标指向要弹出的软键盘的第一“行”,我想要的是我可以触摸屏幕上的任何位置(滚动视图) )然后弹出软键盘。

以下是布局,感谢您的帮助。

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:gravity="top"
            android:padding="10dp"
            android:textSize="16sp"
            android:textColor="@android:color/black">
        </EditText>
    </ScrollView>

    <Button
        android:id="@+id/btnPaste"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/paste"
        android:gravity="center"
        android:onClick="pasteData"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="6dp"
        android:layout_marginBottom="5dp"
        android:background="@drawable/rounded_corner_button"
        android:textColor="@android:color/white"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

布局捕获:

在此输入图像描述

小智 7

在您的ScrollView中添加这一行。

android:fillViewport="true"