Question

I've created a 9-patch background for EditText.

XML code:

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:background="@drawable/searchnew"
    android:ems="10"
    android:hint="  Search recorded files..."
    android:textColor="#646464" >

</EditText>

XML Preview:

enter image description here

Real device:

enter image description here

9-patch image:

enter image description here

To be honest it isn't even bothering me that much, but I'm still wondering why the hell is it happening? Why is the EditText background wider and higher on real device?

Bonus unrelated question: any idea how could I get rid of the "ugly" corners? You can see pixels individually if you look closely, but I want a pixel perfect design.

Was it helpful?

Solution

Just found the reason after doing some more research. The text inside the EditText has some default padding. That's why the 9-patch was stretched more when I ran it on real device. All I had to do was to set padding to 0.

Setting top padding to 0 example:

android:paddingTop="0dp"

Do it like this for top, bottom, left, right and background will stay fixed :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top