views:

27

answers:

1

I want priceText to be right aligned. It is appearing left aligned.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/stocks_gradient">   
    <TextView
        android:id="@+id/nameText"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Symbol" android:textStyle="bold" android:textSize="24sp" android:layout_width="100dp" android:textColor="#4871A8" android:paddingTop="2dip" android:paddingLeft="5dip" android:paddingBottom="1dip"/>
    <TextView
        android:id="@+id/priceText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/nameText"
        android:gravity="right"     
        android:text="100" android:textStyle="bold" android:textSize="24sp" android:textColor="#4871A8" android:paddingTop="2dip" android:paddingBottom="1dip"/>  
    <TextView
        android:id="@+id/changeText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/priceText"
        android:gravity="right"     
        android:textSize="18sp" android:text="3.07(+1.08%)" android:paddingTop="9dip" android:paddingRight="5dip" android:paddingBottom="1dip"/>  
</RelativeLayout>
A: 

What about?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">   
    <TextView
        android:id="@+id/nameText"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Symbol"
        android:textStyle="bold"
        android:textSize="24sp"
        android:layout_width="100dp"
        android:textColor="#4871A8"
        android:paddingTop="2dip"
        android:paddingLeft="5dip"
        android:paddingBottom="1dip"/>
    <TextView
        android:id="@+id/changeText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:gravity="right"     
        android:textSize="18sp"
        android:text="3.07(+1.08%)"
        android:paddingTop="9dip"
        android:paddingRight="5dip"
        android:paddingBottom="1dip"/>  
    <TextView
        android:id="@+id/priceText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/changeText"
        android:gravity="right"     
        android:text="100"
        android:textStyle="bold"
        android:textSize="24sp"
        android:textColor="#4871A8"
        android:paddingTop="2dip"
        android:paddingBottom="1dip"/>  
</RelativeLayout>

EDIT: This is how it looks like:

alt text

Dude, please, go beyond looking at the code. Try to understand what's going on and, more important, give the code a try! You said you wanted to keep it in the same order... so what? Changing order of appearing in a RelativeLayout does not change the component's position. In fact, there are so many case in which you have to put the elements of the XML file in a specific order in order to play with their ID, just how I did in this case.

Cristian
This messes up my UI. I want nameText | priceText | changeText to be next to each other, as they are, but would like priceText to be right-aligned.
Sheehan Alam
Updated. Take a closer look, please ;)
Cristian
@Cristian thanks for helping out. I did try out your XML - here is how it looks: http://cl.ly/d1de362cb09952698d27 this layout is being loaded in a ListView if that makes a difference
Sheehan Alam
Weird... try to play with the with of the first `TextView` (setting it to `fill_parent`). In fact, copy and paste again my code... it makes no sense what I saw in your screenshot.
Cristian
Good call. I cleaned the project and rebuilt it. Now it appears fine. Thanks for the follow-thru @Cristian.
Sheehan Alam