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

标签 android nine-patch

我创建了以下 9-patch PNG 图像

enter image description here

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

enter image description here

如您所见,图片并未填满所有按钮背景!

这是 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 否则它将显示为普通图像

像这样:

enter image description here

关于android - 使用九补丁图像作为按钮android的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18007462/

相关文章:

android - 9-patch 图像和库

java - 如何为布局的宽度和高度设置动画?

java - 如何并排显示 2 个相机预览?[对于纸板应用]

javascript - 是否有允许在 Javascript 中使用 Android 的 9-patches 的工具?

Android - Lollipop/Material Theme - 9 补丁启动显示不正确

android - 为什么给 9-patch png 图像命名为 9 补丁

java - gmail 类似带有复选框的 listView : which ones are selected?

android - 运行时异常 : Error inflating class fragment

java - 有没有什么方法可以将 SHA256 哈希字符串转换为 Java 字符串?

Android Lollipop 5.1 : Fatal signal 11 (SIGSEGV), 代码 2,错误地址 0x9e985ff8 in tid 4093 (RenderThread)/当使用大量 9-patch 图形时