Julian Julian - 1 month ago 6
Android Question

How can i make the three views always be in one line and also always have the same amount of space between them?

my goal is to have the three views in one line no matter how big the display of the device is. Also I want those three views to have the same amount of space between them, so that it will look symmetrical. Are these two things possible and if so, how? Thank you in advance!

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

tools:context="com.juliandrach.eatfit.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">

<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/profilbild"
android:layout_margin="10dp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Ernährungspläne"
android:textAllCaps="true"
android:textSize="21sp"
android:layout_marginTop="15dp"
android:textColor="@android:color/black"
android:layout_weight="2"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Shop"
android:textAllCaps="true"
android:textSize="25sp"
android:textColor="@android:color/black"
android:layout_weight="1"
android:layout_marginTop="15dp"/>
</LinearLayout>
(...)

Answer

Final Check out

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

    tools:context="com.juliandrach.eatfit.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="3"
    android:orientation="horizontal"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@mipmap/ic_launcher"
        android:layout_weight="0"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ernährungspläne"
        android:textAllCaps="true"
        android:textSize="21sp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:textColor="@android:color/black"
        android:layout_weight="1"
        android:id="@+id/textView" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Shop"
        android:textAllCaps="true"
        android:textSize="21sp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:textColor="@android:color/black"
        android:layout_weight="1"
        android:id="@+id/textView1" />

</LinearLayout>
</RelativeLayout>

shifted left