0

I'm trying to set the two textviews in the relative layout to the right, but no luck.. they're laying on the left of the layout:

    <LinearLayout
            android:id="@+id/top_lay2"
            android:layout_width="fill_parent"
            android:layout_marginTop="10dp"
            android:orientation="vertical"
            android:layout_height="wrap_content"
            android:background="@drawable/customrect"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp">

<TextView
            android:id="@+id/font"
            android:layout_marginTop="6dp"
            android:textSize="36sp"
            android:layout_gravity="center"
            android:gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/white1"
            android:text="AllAroundMe"
            style="@style/shadow"
         />
        <RelativeLayout 
            android:background="@drawable/roundedbutton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp">

                <TextView

            android:id="@+id/desc1"
            android:color="@color/white1"
            android:gravity="right"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/desc1"
            android:textColor="@color/tabDark"
            android:padding="6dip"

    />
        <TextView
                    android:id="@+id/desc2"
                    android:color="@color/white1"
                    android:gravity="right"
                    android:layout_below="@id/desc1"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/desc2"
            android:textColor="@color/tabDark"
            android:textStyle="bold"
            android:padding="6dip"/>

           <ImageButton

            android:id="@+id/login"
             android:layout_below="@id/desc2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:src="@drawable/facebooklogin"
             android:onClick="LoginClick"
             android:background="@null"
             android:layout_centerHorizontal="true"/>
                </RelativeLayout>
            <View
                android:layout_below="@id/top_lay2"
                    android:layout_width="fill_parent"
        android:layout_height="5dip"/>
</LinearLayout>
idish
  • 3,190
  • 12
  • 53
  • 85

1 Answers1

1

Hm, I copied your layout to the layout-designer and removed some unavailable drawables und replaced unavailable strings with normal text and it looks quite well (at least right-aligned):

enter image description here

This is my whole layout xml (note the xmlns:android in LinearLayout, that's missing in your code, perhaps that makes the difference?):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/top_lay2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/font"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="6dp"
        android:gravity="center"
        android:text="AllAroundMe"
        android:textColor="#ffffffff"
        android:textSize="36sp" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp" >


        <TextView
            android:id="@+id/desc1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:gravity="right"
            android:padding="6dip"
            android:text="desc1"
            android:textColor="#ff888888"
            android:color="#ffffffff" />


        <TextView
            android:id="@+id/desc2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/desc1"
            android:layout_gravity="right"
            android:gravity="right"
            android:padding="6dip"
            android:text="desc2"
            android:textColor="#ff888888"
            android:textStyle="bold"
            android:color="#ffffffff" />

        <Button
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/desc2"
            android:layout_centerHorizontal="true"
            android:text="Login"
            android:onClick="LoginClick" />
    </RelativeLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:layout_below="@id/top_lay2" />

</LinearLayout>
Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • It doesn't work with long strings such as: http://pastebin.com/4CEBZP69 sorry for the very long text but this is the text that I'm using in my app. anyways you can try some other long strings and you'll see that the text aligns to the left for some reason. Any idea why's that happening? – idish Dec 01 '12 at 13:20
  • Is this hebrew text? Then I suppose the reason for the behavious is that: Hebrew is read from right to left, so perhaps (probably) this inverts the meaning of the android:gravity attribute. See the answer to this question: http://stackoverflow.com/questions/6302221/android-setting-problem-with-textview-for-hebrew-text – Ridcully Dec 01 '12 at 14:46
  • Yep, it is hebrew, but I tried with English also, and happens the same. Try to enter the following text: aba bababa baba ababab ba b babababab ababab aba ba ba ba b aba b aba babab abababab b ababa ababa abababa abababa baba Is happenning the same? – idish Dec 01 '12 at 14:47
  • Hmm.. I'm still in the issue; any idea why it happens? – idish Dec 07 '12 at 18:25