简体   繁体   中英

using nine-patch image as Background of Button android

I have created the following Nine-Patch PNG Image

在此输入图像描述

but when I add it as a background for a button I have got the following result :

在此输入图像描述

as you can see the picture not fill all the button Background !

here is the XML Layout File :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@drawable/ninepatchimage"
        android:text="Click ME" />
</LinearLayout>

can any one tell me why ??

Looking at the image it appears that the image ins't being parsed as a 9patch, it should be saved as img.9.png if not it will appear as a normal image

Like this:

在此输入图像描述

如今在AndroidStudio,你可以采取任何图像从资源,然后右键单击它并选择“创建9补丁文件”,然后使用内置的9补丁编辑器进行配置,如expained 这里

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM