سؤال

I have a set of four 9patch images I wish to use for a button (ldpi to xhdpi). It appears normally on the UI designer in eclipse, but on the emulator and on my android device it stretches the image as if it were not 9patch.

Images (I can only post two links max, sorry):

ldpi http://i.stack.imgur.com/c2D6s.png

mdpi http://i.stack.imgur.com/G7ZzG.png

hdpi (link limit reached, sorry)

xhdpi (link limit reached, sorry)

Here is the button XML:

<Button
    android:id="@+id/button1"
    style="@style/loginstyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/imageView2"
    android:layout_alignLeft="@+id/imageView1"
    android:layout_alignRight="@+id/imageView1"
    android:layout_marginBottom="97dp"
    android:onClick="onLogin"
    android:padding="0dp"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:text="Login"
    android:textColor="#fff" />

Here is my style code:

<style name="loginstyle">
<item name="android:background">@drawable/loginbuttondr</item>
</style>

Here is my drawable xml (loginbuttondr.xml):

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@drawable/loginbutton"/>
</selector>

The image set is named loginbutton.9.png

SOLUTION: Thanks to @MoshEsran. The issue was that I had not added the fill guidelines (right and bottom sides) to the image.

هل كانت مفيدة؟

المحلول

Problem might be your patch line color is not pure black.

You must use #000000, however, currently you are having #101a05

نصائح أخرى

A 9Patch image is intended to be stretchable. That is their function. If the buttons do not look as you wanted, then it is likely that either;

a) Your button layout XML is incorrect for what you want to achieve (add it to your question so we can have a look).

or

b) You haven't provided 9Patch images at the correct resolution for your device.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top