Search code examples
javaandroidxmleclipsenine-patch

Android - Strange Nine Patch Shadow


I'm not sure what exactly is causing the following, perhaps a cache setting or something?

Here is my 9 patch:

enter image description here

Here it is as a PSD screenshot:

enter image description here

Here it is in Eclipse's Layout Designer:

enter image description here

And, here it is as captured by DDMS' screenshot tool on a new Galaxy S3:

enter image description here

See the weird horizontal blur? It's right at the top.

Here is the XML for that bit of layout:

    <TextView
        android:id="@+id/temp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bubble16"
        android:padding="10dp"
        android:text="@string/temp_comment_3"
        android:textColor="#282828"
        android:textSize="17sp" 
        android:textStyle="italic" />

SDK settings:

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="14" />

Solution

  • It's getting scaled up, and the anti-aliasing is causing an in-between gray pixel to bleed into your content area. Same thing is happening to the outer line (it's 2 pixels instead of 1, and the outer area is slightly lighter.)

    I'm going to guess you just have this image in res/drawable, whereas you need to either:

    1. Make larger versions for both res/drawable-hdpi (1.5x larger), and res/drawable-xhdpi (2x larger). Create these folders if they don't exist -- the S3 is an XHDPI device.

    2. Place the 9-patch in res/drawable-nodpi which will prevent it from being scaled, but the size won't be consistent between devices. (e.g. it will be smaller on higher density devices)