How to put button next to two text fields

0

I want the button next to the edit text, I've made several attempts with layout_toleftof and layout weight but the button ends up disappearing, or it stays in the same place. My xml looks like this:

<?xml version="1.0" encoding="utf-8"?>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal"
    android:digits="1234567890.,"
    android:ems="10"
    android:id="@+id/editTextComercial"
    android:hint="Diametro Comercial"
    android:maxLines="1" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="3dp"
    android:inputType="numberDecimal"
    android:digits="1234567890.,"
    android:ems="10"
    android:id="@+id/editTextVC"
    android:hint="Velocidade de Corte"
    android:maxLines="1" />

<Button
    android:text="Calcular "
    android:layout_marginTop="5dp"
    android:layout_height="wrap_content"
    android:id="@+id/buttonCalc"
    android:layout_width="match_parent"/>

<TextView
    android:text="TextView"
    android:visibility="invisible"
    android:gravity="center"
    android:textSize="16dp"
    android:textStyle="bold"
    android:layout_marginTop="5dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textViewResultRPM" />

    
asked by anonymous 30.12.2016 / 02:55

1 answer

2

If you want to do this:

Ihavetwosolutions,onewithLinearanotherwithrelativelayour,followsLinear,initIcreatedotherlayoutsinside,onewithverticalorientationtoputtheEdittext,andanotherhorizontaltoseparatethislayoutfromtheEdittextwiththebuttonbyweight.

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        >
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal"
            android:digits="1234567890.,"
            android:ems="10"
            android:id="@+id/editTextComercial"
            android:hint="Diametro Comercial"

            android:maxLines="1" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="3dp"
            android:inputType="numberDecimal"
            android:digits="1234567890.,"
            android:ems="10"
            android:id="@+id/editTextVC"
            android:hint="Velocidade de Corte"
            android:maxLines="1" />

    </LinearLayout>
    <Button
        android:text="Calcular "
        android:layout_marginTop="5dp"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/buttonCalc"
        android:layout_weight="2"

        />
</LinearLayout>




<TextView
    android:text="TextView"
    android:visibility="invisible"
    android:gravity="center"
    android:textSize="16dp"
    android:textStyle="bold"
    android:layout_marginTop="5dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textViewResultRPM" />

In the relative layout it was a bit more complicated, but the solution is simpler, just add: android:layout_toEndOf="@id/editTextComercial" android:layout_alignBottom="@id/editTextVC" to power the button at the end of the width and bottom of the Edit text, of course a value must be added in width two Edit text.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal"
    android:digits="1234567890.,"
    android:ems="10"
    android:id="@+id/editTextComercial"
    android:hint="Diametro Comercial"
    android:maxLines="1"
    android:layout_marginTop="10dp"
    android:layout_alignParentStart="true" />

<TextView
    android:text="TextView"
    android:visibility="invisible"
    android:gravity="center"
    android:textSize="16dp"
    android:textStyle="bold"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:id="@+id/textViewResultRPM"
    android:layout_below="@+id/editTextVC"
    android:layout_alignParentStart="true" />

<EditText
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal"
    android:digits="1234567890.,"
    android:ems="10"
    android:id="@+id/editTextVC"
    android:hint="Velocidade de Corte"
    android:maxLines="1"
    android:layout_below="@+id/editTextComercial"
    android:layout_alignParentStart="true" />

<Button
    android:text="Calcular "
    android:layout_height="wrap_content"
    android:id="@+id/buttonCalc"
    android:layout_width="match_parent"
    android:layout_toEndOf="@id/editTextComercial"
    android:layout_alignBottom="@id/editTextVC"
    android:layout_alignTop="@+id/editTextComercial" />

    
30.12.2016 / 13:45