0

I have defined the 2 EditTexts in a LinearLayout:

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

In code I only change their typeface and textcolor:

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

Both have the identical code (except the id) and should only have one line and scroll vertically. eT_eingabe does so. eT_ausgabe always has one line, but on a device with API 21 (Huawei Honor 7, real device) still does allow to scroll vertically (The user can move the text slightly up and down). On API 24 (Pixel 3, emulator) everything works fine.

My question is: how can I prevent the edittext eT_ausgabe from scrolling up and down?

Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18

2 Answers2

0

If you want to disable editText scrolling use this code :

eT_ausgabe.setMovementMethod(null);
Mona Baharlou
  • 1,401
  • 1
  • 13
  • 26
0

Thanks for all responds! I solved my problem like this. I created a parent Linear Layout over above the Linear Layout and limited its height to 150sp. My solution looks like this:

<LinearLayout
    android:id="@+id/m_display"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="20dp"
    android:layout_marginRight="15dp"
    android:layout_marginBottom="10dp"
    android:background="@drawable/displayshape"
    android:baselineAligned="false">

    <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/m_eT_Eingabe"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="20dp"
            android:layout_marginTop="5sp"
            android:layout_weight="1"
            android:width="100dp"
            android:background="#00464646"
            android:fontFamily="monospace"
            android:inputType="textNoSuggestions"
            android:maxLines="1"
            android:minHeight="55sp"

            android:scrollbars="horizontal"
            app:autoSizeMaxTextSize="100sp"
            app:autoSizeMinTextSize="12sp"
            app:autoSizeStepGranularity="1sp" />

        <EditText
            android:id="@+id/m_eT_Ausgabe"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="20dp"
            android:layout_marginTop="5sp"
            android:layout_weight="1"
            android:width="100dp"
            android:background="#00464646"
            android:fontFamily="monospace"
            android:inputType="textNoSuggestions"
            android:maxLines="1"
            android:minHeight="55sp"

            android:scrollbars="horizontal"
            android:scrollHorizontally="true"
            app:autoSizeMaxTextSize="100sp"
            app:autoSizeMinTextSize="12sp"
            app:autoSizeStepGranularity="1sp" />

    </LinearLayout>
</LinearLayout>