开发者

My TextView is not appearing right aligned

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"
        andro开发者_开发百科id: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>


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:

My TextView is not appearing right aligned

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜