When entering data into Edittext, do one Textview and one Edittext start moving?

Asked

Viewed 821 times

0

At first everything is normal:

inserir a descrição da imagem aqui

Something really strange happens when I insert some content in Edittext:

inserir a descrição da imagem aqui

A Textview and an Edittext start to move to the right, as I insert characters, whatever they are, infrequently, until they leave the screen:

inserir a descrição da imagem aqui

What is the explanation for this? How to solve?

Activity:

package genesysgeneration.ruleoftree;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

public class Main02Activity extends AppCompatActivity {

    private EditText etProduto01;
    private TextView tvFinalResult;
    private String produto;
    private EditText etPreco01, etPreco02, etQuantidade01, etQuantidade02, etUnidade01, etUnidade02;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main02);

        etProduto01=(EditText)findViewById(R.id.etProduto01);
        etProduto01.setHint("opcional");

        etQuantidade01=(EditText)findViewById(R.id.etQuantidade01);
        etQuantidade02=(EditText)findViewById(R.id.etQuantidade02);
        etQuantidade01.setHint("g ou ml");
        etQuantidade02.setHint("g ou ml");

        addPreco();

        etUnidade01=(EditText)findViewById(R.id.etUnidade01);
        etUnidade02=(EditText)findViewById(R.id.etUnidade02);

        tvFinalResult=(TextView)findViewById(R.id.tvFinalResult);
        tvFinalResult.setText(String.valueOf(""));

        addProduto();

    }

    private void addPreco(){

    }

    private void addProduto(){

        etProduto01.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                produto=s.toString();
                tvFinalResult.setText(String.valueOf(produto));

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    }

}

Note that the above code is in development, I stopped developing it because of this bizarre BUG.

xml layout.:

<?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:id="@+id/activity_main02"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="genesysgeneration.ruleoftree.Main02Activity">

    <TextView
        android:text="Produto:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/tvLabelProduto"
        android:textSize="18sp"
        android:textStyle="normal|bold" />

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_below="@+id/tvLabelProduto"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/etProduto01" />

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:id="@+id/etPreco01"
        android:layout_below="@+id/tvLabelPreco01"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:text="Preço 2:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tvLabelPreco02"
        android:layout_alignTop="@+id/tvLabelPreco01"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="18sp"
        android:textStyle="normal|bold" />

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_below="@+id/tvLabelPreco02"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/etPreco02" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/tvFinalResult" />

    <TextView
        android:text="Quantidade 1:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etPreco01"
        android:layout_toRightOf="@+id/tvFinalResult"
        android:layout_toEndOf="@+id/tvFinalResult"
        android:layout_marginTop="37dp"
        android:id="@+id/tvLabelQuantidade01"
        android:textStyle="normal|bold"
        android:textSize="18sp" />

    <TextView
        android:text="Quantidade 2:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tvLabelQuantidade02"
        android:textSize="18sp"
        android:textStyle="normal|bold"
        android:layout_alignBottom="@+id/tvLabelQuantidade01"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_below="@+id/tvLabelQuantidade01"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/etQuantidade01" />

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:id="@+id/etQuantidade02"
        android:layout_below="@+id/tvLabelQuantidade02"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:text="Unidades 1:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:id="@+id/tvLabelUnidade01"
        android:layout_below="@+id/etQuantidade01"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="18sp"
        android:textStyle="normal|bold" />

    <TextView
        android:text="Unidades 2:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/tvLabelUnidade01"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/tvLabelUnidade02"
        android:textStyle="normal|bold"
        android:textSize="18sp" />

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_below="@+id/tvLabelUnidade01"
        android:layout_toRightOf="@+id/tvFinalResult"
        android:layout_toEndOf="@+id/tvFinalResult"
        android:id="@+id/etUnidade01" />

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:layout_below="@+id/tvLabelUnidade02"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/etUnidade02" />

    <TextView
        android:text="Preço 1:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="73dp"
        android:id="@+id/tvLabelPreco01"
        android:textSize="18sp"
        android:textStyle="normal|bold"
        android:layout_below="@+id/etProduto01"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

  • Put the xml from this view.

  • 1

    Place the xml of the activity_main02 layout integer

1 answer

1


The problem is in the property android:layout_toRightOf="@+id/tvFinalResult", used by Texview: Quantity1 and Edittext of Unit 1, as you reference the positioning based on Edittext, when you modify a field value, the position reference also changes. Substitute android:layout_toRightOf="@+id/tvFinalResult" for android:layout_alignParentLeft="true". The XML is below:

   <?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:id="@+id/activity_main02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="genesysgeneration.ruleoftree.Main02Activity">
<TextView
    android:text="Produto:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/tvLabelProduto"
    android:textSize="18sp"
    android:textStyle="normal|bold" />

<EditText
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_below="@+id/tvLabelProduto"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/etProduto01" />

<EditText
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/etPreco01"
    android:layout_below="@+id/tvLabelPreco01"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<TextView
    android:text="Preço 2:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvLabelPreco02"
    android:layout_alignTop="@+id/tvLabelPreco01"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:textSize="18sp"
    android:textStyle="normal|bold" />

<EditText
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_below="@+id/tvLabelPreco02"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/etPreco02" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/tvFinalResult" />

<TextView
    android:text="Quantidade 1:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/etPreco01"
    android:layout_alignParentLeft="true"
    android:layout_toEndOf="@+id/tvFinalResult"
    android:layout_marginTop="37dp"
    android:id="@+id/tvLabelQuantidade01"
    android:textStyle="normal|bold"
    android:textSize="18sp" />

<TextView
    android:text="Quantidade 2:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvLabelQuantidade02"
    android:textSize="18sp"
    android:textStyle="normal|bold"
    android:layout_alignBottom="@+id/tvLabelQuantidade01"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<EditText
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_below="@+id/tvLabelQuantidade01"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/etQuantidade01" />

<EditText
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/etQuantidade02"
    android:layout_below="@+id/tvLabelQuantidade02"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<TextView
    android:text="Unidades 1:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="32dp"
    android:id="@+id/tvLabelUnidade01"
    android:layout_below="@+id/etQuantidade01"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:textSize="18sp"
    android:textStyle="normal|bold" />

<TextView
    android:text="Unidades 2:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/tvLabelUnidade01"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/tvLabelUnidade02"
    android:textStyle="normal|bold"
    android:textSize="18sp" />

<EditText
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_below="@+id/tvLabelUnidade01"
    android:layout_alignParentLeft="true"
    android:layout_toEndOf="@+id/tvFinalResult"
    android:id="@+id/etUnidade01" />

<EditText
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_below="@+id/tvLabelUnidade02"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/etUnidade02" />

<TextView
    android:text="Preço 1:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="73dp"
    android:id="@+id/tvLabelPreco01"
    android:textSize="18sp"
    android:textStyle="normal|bold"
    android:layout_below="@+id/etProduto01"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

   </RelativeLayout>
  • Vlw bro!!! When I modify the line in question, the line then (android:layout_toEndOf="@+id/tvFinalResult") has error there was just delete and everything worked out.

  • No problem, the community is to help us. About the error this line: (android:layout_toEndOf="@+id/tvFinalResult") presented with you, can you say what was the problem? In mine compiled and rotated right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.