首页 > 解决方案 > 如何使 EditText 在 X 行后自动滚动

问题描述

我已经找到了很多关于如何制作可滚动 EditText 的答案,但没有人提到如何在 X 行后使文本滚动。在我的应用程序中,我需要在 5 行后自行滚动文本,否则文本会与下面的图标混淆。到目前为止,我一直在限制 maxLength 以避免这种情况,但我需要能够编写更多字符而不用担心它们与图标混淆。

<EditText
    android:id="@+id/resultText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:textColorHint="@color/white"
    android:textColor="@color/colorPrimaryDark"
    android:textIsSelectable="true"
    android:gravity="top"
    android:fontFamily="sans-serif"
    android:textSize="25dp"
    android:textStyle="normal"
    android:ems="30"
    android:maxLength="180"
    android:hint="Input here..."
    android:textAlignment="center"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:inputType="textMultiLine"
    android:overScrollMode="always"
    android:scrollbarStyle="insideInset"/>

标签: androidxmlandroid-layout

解决方案


原来我正在寻找的是:

android:lines="5"

推荐阅读