Search code examples
androidbackgroundscalenine-patch

Android 9-Patch scaling issue


I am having scaling problems when using the 9-patch images for the background of EditText fields. I have a table which stretches the entire width, inside here I have the following tablerow which fills the width of the table.

The problem is that I am using a 9-patch image as the background but the edit text field is not stretching to the entire width, it only stretches to the width of the hint text.

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal" >

    <EditText
        android:id="@+id/et_username"
        android:contentDescription="@string/hint_enterUsername"
        android:hint="@string/hint_enterUsername"
        android:singleLine="true"
        android:textSize="@dimen/edittext_textsize"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"                    
        android:gravity="center_horizontal|center_vertical"
        android:background="@drawable/background_field_top" />

</TableRow>

I can see in the graphical view that the width of the row does stretch but the EditText field does not, as shown in the attached image

Graphical View

Has anyone any ideas on how to make the edittext stretch to the entire size? The following is the 9-patch image I'm using.

9-patch image


Solution

  • your is working fine for me ..i am using my own 9 patch... here is my code :

            <LinearLayout
                android:id="@+id/layout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
    
                <TableRow
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical|center_horizontal" >
    
                    <EditText
                        android:id="@+id/et_username"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/areanumber"
                        android:gravity="center_horizontal|center_vertical"
                        android:singleLine="true"
                        android:text="hello" />
                </TableRow>
            </LinearLayout>
    

    here areanumber is my 9 patch image... just try to wrap your code inside linearlayout i implemented your 9 patch image and its also working fine

    enter image description here