how do i adjust the textview in an android device to align with the edittext position?

To solve the scrolling issue you have to change your xml file and put both EditText and TextView in a single parent View wrapping to its content which is inside a scrollview, so now the whole view will be scrollable. Below is the new xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <RelativeLayout
        android:layout_width="40dp"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:background="#eee"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/containerRl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/lineNumber"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:background="#eee"
                android:gravity="center_horizontal"
                android:padding="10dp"
                android:text="1"
                android:textSize="18sp"
                tools:layout_editor_absoluteY="12dp" />

            <EditText
                android:id="@+id/fileText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_toEndOf="@+id/lineNumber"
                android:ems="10"
                android:padding="10dp"
                android:gravity="left|top"
                android:inputType="textMultiLine"
                android:scrollbars="vertical"/>
        </RelativeLayout>

    </ScrollView>

</RelativeLayout>

And remove the lines of code in my previous answer.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top