How to position elements in Android

  android, android-layout, java

I need to position the elements on the left and right so that the distance on both sides is the same. It needs to be done without margins, does anyone know how? Thanks, my code is below.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#00679F">

    <LinearLayout
        android:id="@+id/prvired"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_120sdp"
        android:gravity="center_horizontal"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/logo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_50sdp"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_marginBottom="@dimen/_10sdp"
            android:src="@drawable/logo" />


    </LinearLayout>


    <!--android:layout_below="@+id/start"-->


    <LinearLayout
        android:id="@+id/drugiRed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginLeft="@dimen/_17sdp"
        android:orientation="horizontal">
        <!--android:layout_below="@+id/start"-->


        <RelativeLayout
            android:layout_width="@dimen/_53sdp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_marginTop="@dimen/_120sdp"
            android:layout_marginRight="@dimen/_20sdp"
            android:background="#00679F"
            android:gravity="center_horizontal">


            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/sva_vozila"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_gravity="center_horizontal"

                android:layout_marginRight="@dimen/_8sdp"
                android:layout_marginBottom="@dimen/_minus26sdp"
                android:text="Unos"
                android:textColor="#FFFFFF"
                android:textSize="@dimen/_17ssp" />

            <ImageButton
                android:id="@+id/sva_vozila"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="@dimen/_25sdp"
                android:layout_marginBottom="@dimen/_20sdp"
                android:background="#00679F"
                android:src="@drawable/input60" />

            <TextView
                android:layout_width="11dp"
                android:layout_height="5dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="70dp"
                android:textColor="#F8C304" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="@dimen/_76sdp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_25sdp"
            android:layout_marginTop="@dimen/_120sdp"
            android:layout_marginRight="@dimen/_1sdp"
            android:background="#00679F"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="2dp"
                android:layout_marginEnd="22dp"
                android:layout_marginRight="15dp"
                android:layout_marginLeft="5dp"
                android:layout_marginBottom="-23dp"
                android:text="Voznja"
                android:textColor="#FFFFFF"
                android:textSize="@dimen/_17ssp" />

            <ImageButton
                android:id="@+id/listaImg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="@dimen/_26sdp"
                android:background="#00679F"
                android:contentDescription="TODO"
                android:onClick="getSvaVozila"
                android:src="@drawable/sedan260" />


        </RelativeLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/treciRed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginLeft="@dimen/_17sdp"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="@dimen/_100sdp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_35sdp"
            android:layout_marginTop="@dimen/_200sdp"
            android:layout_marginRight="@dimen/_10sdp"
            android:background="#00679F"
            android:gravity="center_horizontal">

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="@dimen/_14sdp"
                android:layout_marginLeft="@dimen/_13sdp"
                android:layout_marginBottom="@dimen/_minus23sdp"
                android:text="Pregled"
                android:textColor="#FFFFFF"
                android:textSize="@dimen/_17ssp" />

            <ImageButton
                android:id="@+id/sveVoznjeImg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="@dimen/_15sdp"
                android:layout_marginTop="@dimen/_25sdp"
                android:background="#00679F"
                android:src="@drawable/chart60" />

            <TextView
                android:layout_width="@dimen/_11sdp"
                android:layout_height="@dimen/_5sdp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/_70sdp"
                android:layout_marginRight="@dimen/_60sdp"
                android:gravity="center"
                android:textColor="#F8C304" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/idEnd"
            android:layout_width="@dimen/_130sdp"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_200sdp"
            android:background="#00679F"
            android:gravity="center_horizontal"
            android:orientation="vertical">


            <ImageButton
                android:id="@+id/vozila"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginRight="@dimen/_30sdp"
                android:layout_marginTop="@dimen/_27sdp"
                android:background="#00679F"
                android:onClick="getSvaVozila"
                android:src="@drawable/shutdown60" />

            <TextView
                android:id="@+id/textview5"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/_23sdp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="@dimen/_56sdp"
                android:text="Odjava"
                android:textColor="#FFFFFF"
                android:textSize="@dimen/_17ssp" />


        </RelativeLayout>
    </LinearLayout>
    <android.support.design.widget.BottomNavigationView

        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/main_manu"
        app:labelVisibilityMode="labeled"
        app:itemBackground="@color/blue"
        app:itemIconTint="@android:color/white"
        app:itemTextColor="@android:color/white" />

</RelativeLayout>

enter image description here

Source: Android Questions

LEAVE A COMMENT