Android Studio switching position of TextView and Plain Text input

66 Views Asked by At

I'm working on an Android application, and admittedly I'm a bit of a newbie. I'm working on a very simple input of some information, and found something very odd. Whenever I run the application in a virtual device, Android Studio flips the position of the input labels (TextView objects), and the inputs themselves (PlainText objects).

It's best to see what I mean here:

Example of flipping positions

In the GIF above, I'm clicking the Play button on the emulator; after that, the positions flip. Strange right? Is there something I have defined in the XML layout that's causing this? Or something I'm doing wrong?

For example, here's the raw XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".ui.currentjob.CurrentJobFragment">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal">
      <TextView
        android:id="@+id/someTitle"
        android:textStyle="bold|italic"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Some Title"
        android:textSize="20sp" />
    </LinearLayout>

    <!-- Input 1 -->
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal">
      <EditText
        android:id="@+id/input1"
        android:layout_width="146dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textPersonName"
        android:textSize="16sp" />
      <TextView
        android:id="@+id/labelInput1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="right|center_vertical"
        android:text="Input 1"
        android:textSize="16sp" />
    </LinearLayout>

    <!-- Input 2 -->
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal">
      <EditText
        android:id="@+id/input2"
        android:layout_width="154dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textPersonName"
        android:textSize="16sp" />
      <TextView
        android:id="@+id/labelInput2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="right|center_vertical"
        android:text="Input 2"
        android:textSize="16sp" />
    </LinearLayout>

  </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
1

There are 1 best solutions below

0
Scott Crooks On

I figured it out about 1 minute after posting this. The problem was that Rearrange code was checked under the Actions on Save setting. See the image below:

Rearrange code was checked on Actions on Save