Android Studio aligning elements to other elements under them

Viewed 132

Hello I'm using android studio for mobile app development and I need to make 3 LinearLayouts the same size. The problem is that the first element contains different element. I need to stretch first element to have exactly the same size as others. I guess I can somehow get to know that is the size of elements and set the value to the first element. Maybe there is a possibility to align them somehow? That is how it looks. Thanks for help!

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:gravity="center_horizontal"
    tools:context=".MainView.MainActivity"
    android:orientation="vertical"
    android:paddingTop="100dp">


    <!--    rounds View   -->
    <TextView
        style="@style/option_type_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/rounds" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

        <Button
            android:id="@+id/minus_round_button"
            style="@style/change_value_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/minus" />

        <EditText
            android:id="@+id/round_minutes"
            style="@style/option_input_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/default_time" />

        <Button
            android:id="@+id/plus_round_button"
            style="@style/change_value_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/plus"/>
    </LinearLayout>
    <!--    end rounds View-->
    <!--    work View   -->
    <TextView
        style="@style/option_type_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/work" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

        <Button
            android:id="@+id/minus_work_button"
            style="@style/change_value_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/minus" />

        <EditText
            android:id="@+id/work_minutes"
            style="@style/option_input_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/default_time" />
        <TextView
            style="@style/option_input_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=":"/>
        <EditText
            android:id="@+id/work_seconds"
            style="@style/option_input_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/default_time" />
        <Button
            android:id="@+id/plus_work_button"
            style="@style/change_value_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/plus"/>
    </LinearLayout>
    <!--    end Work View-->
    <!--    rest View   -->
    <TextView
        style="@style/option_type_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/rest" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

        <Button
            android:id="@+id/minus_rest_button"
            style="@style/change_value_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/minus" />

        <EditText
            android:id="@+id/rest_minutes"
            style="@style/option_input_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/default_time" />
        <TextView
            style="@style/option_input_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=":"/>
        <EditText
            android:id="@+id/rest_seconds"
            style="@style/option_input_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/default_time" />
        <Button
            android:id="@+id/plus_rest_button"
            style="@style/change_value_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/plus"/>
    </LinearLayout>
    <!--    end Rest View-->

    </LinearLayout>
1 Answers

Make your first element as follows:

<TextView
    style="@style/option_type_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/rounds" />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center">

    <Button
        android:id="@+id/minus_round_button"
        style="@style/change_value_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/minus" />

    <EditText
        android:id="@+id/round_minutes"
        style="@style/option_input_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/default_time" />
    
    <Button
        android:id="@+id/plus_round_button"
        style="@style/change_value_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/plus"/>
</LinearLayout>
Related