Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用九块补丁图像作为android按钮的背景_Android_Nine Patch - Fatal编程技术网

使用九块补丁图像作为android按钮的背景

使用九块补丁图像作为android按钮的背景,android,nine-patch,Android,Nine Patch,我已经创建了以下九个补丁PNG图像 但当我将其添加为按钮的背景时,我得到了以下结果: 正如你所见,图片并没有填满所有的按钮背景 以下是XML布局文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" a

我已经创建了以下九个补丁PNG图像

但当我将其添加为按钮的背景时,我得到了以下结果:

正如你所见,图片并没有填满所有的按钮背景

以下是XML布局文件:

<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>


有人能告诉我为什么吗?

查看图像,图像似乎没有被解析为9patch,它应该保存为
img.9.png
如果没有,它将显示为正常图像

像这样:


9-patch可以解决您的问题 在这里:


并在此处搜索“九补丁”:现在在AndroidStudio中,您只需从资源中获取任何图像,右键单击并选择“创建9补丁文件”,然后使用内置的9补丁编辑器对其进行配置,如前所述。

我使用此工具创建了九块补丁图像,可能不需要填充就可以尝试。选定的图像保存为img.9.png,但当我将其作为图标集图像添加到项目中时,我检查了图像的名称,并且它是可绘制文件夹中的img.png!!!这里有问题吗???是的,它需要像上面的图像一样。你可以直接将图像拖到文件夹中。好的,我会试试:)但是我应该将图片拖到哪个可绘图文件夹中??