Android EditText:仅水平滚动

时间:2019-12-16 12:05:07

标签: android

我已经在LinearLayout中定义了2个EditText:

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:baselineAligned="false"
            android:minHeight="120dp"
            android:orientation="vertical">

            <EditText
                android:id="@+id/eT_eingabe"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="20dp"
                android:layout_marginTop="5sp"
                android:width="100dp"
                android:background="#00464646"
                android:inputType="textNoSuggestions"
                android:singleLine="true"
                android:maxLines="1"
                android:minHeight="55sp"
                app:autoSizeMaxTextSize="100sp"
                app:autoSizeMinTextSize="12sp"
                app:autoSizeStepGranularity="1sp"
                />

            <EditText
                android:id="@+id/eT_ausgabe"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="20dp"
                android:layout_marginTop="5sp"
                android:width="100dp"
                android:background="#00464646"
                android:inputType="textNoSuggestions"
                android:singleLine="true"
                android:maxLines="1"
                android:minHeight="55sp"
                app:autoSizeMaxTextSize="100sp"
                app:autoSizeMinTextSize="12sp"
                app:autoSizeStepGranularity="1sp" />
        </LinearLayout>
    </LinearLayout>

在代码中,我仅更改其字体和文本颜色:

view.setTextColor(tc);
view.setTypeface(tf);

两者都具有相同的代码(ID除外),并且只能有一行并且垂直滚动。 eT_eingabe这样做。 eT_ausgabe始终只有一行,但是在具有API 21的设备(Huawei Honor 7,真实设备)上仍然允许垂直滚动(用户可以稍微上下移动文本)。在API 24(像素3,仿真器)上,一切正常。

我的问题是:如何防止EditText eT_ausgabe上下滚动?

2 个答案:

答案 0 :(得分:0)

如果要禁用editText滚动,请使用以下代码:

eT_ausgabe.setMovementMethod(null);

答案 1 :(得分:0)

感谢大家的回应! 我这样解决了我的问题。我在“线性布局”上方创建了父线性布局,并将其高度限制为150sp。我的解决方案如下所示:

a: -->1            <-- len = 1
相关问题