rmaik
rmaik

Reputation: 1086

layout_below doesn't work in RelativeLayout

In the below XML layout, I am trying to make each value(accXValue, accYValue,accZValue) appear to the right of their respective label as shown below in the code.

At runtime, all the values are placed over each other to the right of the (tv_accX_label), all the values overlap each other and located in one position despite the fact that I specified the attributes layout_below.

Please let me know what I am missing.

XML:

<?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">
<TextView 
    android:id="@+id/tv_accX_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:text="Acc[X]: "/>
<TextView 
    android:id="@+id/tv_accX_value"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/tv_accX_label"/>

<TextView 
    android:id="@+id/tv_accY_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/tv_accX_label"
    android:text="Acc[Y]: "/>
<TextView 
    android:id="@+id/tv_accY_value"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@+id/tv_accY_label"/>

<TextView 
    android:id="@+id/tv_accZ_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/tv_accY_label"
    android:text="Acc[Z]: "/>
<TextView 
    android:id="@+id/tv_accZ_value"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@+id/tv_accZ_label"/>

<Button 
    android:id="@+id/btn_send"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tv_accZ_label"
    android:gravity="center_vertical|center_horizontal"
    android:text="send to frag_2"/>

Upvotes: 0

Views: 2786

Answers (1)

Simas
Simas

Reputation: 44188

valueY is actually displayed to the rightOf labelY. You just didn't provide a below attribute on values, that's why they're stacking on top of each other. This is how:

valueY:

<TextView
    android:text="RIGHT"
    android:id="@+id/tv_accY_value"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tv_accX_value"
    android:layout_toRightOf="@+id/tv_accY_label"
    android:layout_toEndOf="@+id/tv_accY_label"/>

valueZ:

<TextView
    android:text="BELOW"
    android:id="@+id/tv_accZ_value"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tv_accY_label"
    android:layout_toRightOf="@+id/tv_accY_label"
    android:layout_toEndOf="@+id/tv_accY_label"/>

Upvotes: 2

Related Questions