XML : Why does using layout_below mess up the size of the start button?

I have the following 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:layout_width="match_parent"      android:layout_height="match_parent"      android:background="@color/light_blue"      tools:context=".StoppedActivity">    <TextView      android:id="@+id/totalTimeView"      android:layout_width="80dp"      android:layout_height="50dp"      android:layout_marginBottom="90dp"      android:layout_alignParentTop="true"      android:background="@android:color/white"      android:textColor="@color/started_black"      />    <TextView      android:id="@+id/countDownView"      android:layout_below="@+id/totalTimeView"      android:layout_centerHorizontal="true"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:background="@drawable/white_circle"      android:textColor="@color/started_black"      android:gravity="center"      android:textSize="65sp" />    <ImageButton      android:id="@+id/settings"      android:layout_width="60dp"      android:layout_height="50dp"      android:layout_alignParentTop="true"      android:layout_alignParentRight="true"      android:src="@drawable/ic_settings_black_24dp"      android:scaleType="fitXY"      />    <ImageButton      android:id="@+id/startButton"      android:background="@drawable/button_selector"      android:layout_width="360dp"      android:layout_height="70dp"      android:layout_alignParentBottom="true"      android:layout_centerInParent="true"      android:layout_marginBottom="60dp" />    <ToggleButton      android:id="@+id/toggleSwitch"      android:background="@drawable/toggle_selector"      android:layout_centerInParent="true"      android:layout_below="@+id/countDownView"      android:layout_marginTop="40dp"      android:layout_width="300dp"      android:layout_height="50dp" />  </RelativeLayout>    

before adding the line

Currently it displays everything correctly on Nexus 5X, but the layout gets messed up when used in a device with a different screen size. To ensure that doesn't happen, I added the line

  android:layout_below="@id/toggleSwitch"    

to

  <ImageButton      android:id="@+id/startButton"      android:background="@drawable/button_selector"      android:layout_width="360dp"      android:layout_height="70dp"      android:layout_alignParentBottom="true"      android:layout_below="@id/toggleSwitch"      android:layout_centerInParent="true"      android:layout_marginBottom="60dp" />    

However, this messes up the sizing of the start button, why is this happening? How do I fix this? Thank you in advance.

after adding the line

No comments:

Post a Comment