Search code examples
androidxmltextviewalignment

Android align textview to right


in Android XML I am try to set the alignment of the text to right:

android:gravity="center_vertical|right"

I also align it in the center of the parent, hence the center add in. Now I have the text on a right alignment but I want to assign it to the position of the parents left:

android:layout_alignParentLeft="true"

But this only keeps the alignment of the text and does not align to the parents center? Heres the entire view xml code:

<TextView
    android:id="@+id/textview_example"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical|right"
    android:layout_alignParentLeft="true"
    android:textColor="#474747"
    android:textSize="14sp" />

Can someone help me create a solution for having the textview's text aligned to the right but be assigned to the parents left?


Solution

  • Actually ur code is working but it will be clear if you give width less than parent, try this change

    <TextView
            android:id="@+id/textview_example"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|right"
            android:textColor="#474747"
            android:text="ABAGSADGDBAJDHADNA"
            android:textSize="14sp" />