Android TextView Align text to Right and Left
android
Solution
Here's another method:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_common">
<TextView
android:text="Left Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"/>
<TextView
android:text="Right Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"/>
</FrameLayout>
Layout_gravity tells the parent where to put the child. In a FrameLayout, children can go anywhere and are unobstructed by other children. If there is overlap, the last child added is on top. Good luck!
Problem
I'm trying to have a TextView that has two pieces of text, one aligned against the far left and one against the far right. I can put spaces between the two words, but I was wondering if there is a better technique? ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background_common" android:id="@+id/LinearLayout0123"> <TextView android:layout_width="300dp" android:layout_height="40dp" android:textColor="@color/Black" android:textStyle="bold" android:textSize="15dp" android:paddingLeft="10dp" android:paddingTop="10dp" android:layout_marginTop="10dp" android:layout_marginLeft="10dp" android:background="@drawable/selector_social_facebook_twitter" android:text="Right Text Left Text" /> </LinearLayout> ```