Android align textview to right
26,502
Solution 1
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" />
Solution 2
Try this....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#E6F2B2"
android:gravity="center"
android:padding="3dp" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="end|center"
android:text="@string/title"
android:textColor="#323232"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
Author by
Vesica Piscis
Updated on October 30, 2021Comments
-
Vesica Piscis over 2 years
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?