Another possible way to do this is to use the layout_weight attribute. This is my preference because it fills all the free space.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/open_file_name" android:layout_width="0dp" android:layout_weight="3" android:layout_height="match_parent" android:layout_gravity="start|left" android:gravity="start|left" android:padding="5dp" android:text="TextView" /> <Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:gravity="end|right" android:text="open" /> </LinearLayout>
source share