I have some text with a transparent background like so

Now when the text is small it looks nice and centered (also I have android:minWidth=”150dip”) like above but since it is wrap_content when the text is large

it wraps like this.
Is there a way I can always have a constant space between the edges of the background and the text and also have the text centered(which would be obvious once the sides were fixed)
This is my text xml
<TextView
android:id="@+id/title2"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/tocheader"
android:gravity="center_vertical|center_horizontal"
android:minWidth="150dip"
android:text="example"
android:textColor="#ffffff"
android:textSize="18dp"
android:textStyle="bold" />
and @drawable/tocheader is just
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#88000000" />
</shape>
Use the padding instead of margin…
Margin gives you space between this view and the surrounding with none of “this view”s properties.
Padding gives you space between this view and surrounding with all of “this view”s properties.