【问题标题】:using nine-patch image as Background of Button android使用九个补丁图像作为 Button android 的背景
【发布时间】:2019-08-24 06:15:50
【问题描述】:

我创建了以下九个补丁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>

谁能告诉我为什么??

【问题讨论】:

    标签: android nine-patch


    【解决方案1】:

    看图片,图片好像没有被解析为9patch,应该保存为img.9.png,否则会显示为普通图片

    像这样:

    【讨论】:

    • 也许尝试不使用填充
    • 选中的图片保存为img.9.png,但是当我把它作为图标集图片添加到项目中时,我检查了图片的名称,它是在Drawable文件夹中的img.png !!!问题在这里???
    • 是的,需要像上图那样
    • 可以将图片直接拖到文件夹中
    • 好的,我会试试看的:) 但是我应该把图片拖到哪个 Drawable 文件夹中??
    【解决方案2】:

    现在在 AndroidStudio 中,您可以从资源中获取任何图像并右键单击它并选择“创建 9-Patch 文件”,然后使用内置的 9-Patch 编辑器对其进行配置,正如here所解释的那样。

    【讨论】:

      猜你喜欢
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多