I want to center a text inside a TextView relative to the parent layout and not relative to the textview.
Example in this code in want to center text list_title relative to my screen width:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_weight="75"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/list_title" />
<Button
android:layout_weight="15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="90px"
android:text="@string/filter"
android:visibility="gone"
android:id="@+id/button_filter" />
</LinearLayout>
Have you a solution?
Thanks for your help
Hum, it’s not a very good solution, but if you know your title lenght, you can add
to your textview.
Replace 160dip by 160 – lenght of your title / 2, it will be almost centered on all screens…
Edit: or if you want an other solution, you have to use relative layout.