Hey,
I encountered this problem when updating my background to use a 9-patch image. The layout is fine on different screens using different sizes of the same image, but when I change the image to be a 9-patch it breaks the entire layout mysteriously.
The previous layout looks like this:
.
When changed to 9-patch:
.
The XML file remained the same, just the PNG files were altered.
<?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/bg">
<TextView
android:text="@string/title"
android:id="@+id/login_title"
android:layout_width="fill_parent"
android:layout_height="40px"
android:textSize="30px">
</TextView>
<View
android:id="@+id/login_underline"
android:layout_width="wrap_content"
android:layout_height="2px"
android:background="#aaaaaa">
</View>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:stretchColumns="1"
android:gravity="center"
android:paddingLeft="10px"
android:paddingRight="10px">
<TableRow>
<TextView
android:id="@+id/login_usernameLabel"
android:text="@string/login_usernameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5px">
</TextView>
<EditText
android:text=""
android:id="@+id/login_username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:lines="1"
android:nextFocusDown="@+id/login_password">
</EditText>
</TableRow>
<TableRow>
<TextView
android:id="@+id/login_passwordLabel"
android:text="@string/login_passwordLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:text=""
android:id="@+id/login_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusDown="@+id/login_login"
android:inputType="textPassword">
</EditText>
</TableRow>
<TableRow android:gravity="right">
<Button
android:text="@string/login_login"
android:id="@+id/login_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</TableRow>
<TableRow>
<CheckBox
android:id="@+id/login_remember"
android:text="@string/login_remember"
android:layout_span="2">
</CheckBox>
</TableRow>
</TableLayout>
</LinearLayout>
Any ideas? Or other solutions to get non-scaled, centered background?