Android Edittext 测试不会在屏幕边界处停止

Android Edittext test does not stop at screen boundries

我在记事本应用程序的布局中添加了一个 EditText。当我尝试在 EditText 中键入内容时,我意识到如果文本字符串比屏幕边缘长,它将继续沿直线过去,而不是转到下一行。布局代码如下。

<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/noteEditorLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/noteEditor"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:hint="@string/enterText"
        android:textSize="18sp"
        android:background="#00000000"
        android:inputType="textMultiLine|textCapSentences"
        android:gravity="top"
        android:layout_weight="1">
    </EditText>
</LinearLayout>

谢谢。

尝试设置您的

android:layout_width="0dp"

android:layout_width="match_parent"

改为

或者如果您坚持使用 layout_weight 属性,请将此行添加到您的 LinearLayout

android:weightSum="1"