所以我正在尝试 9 补丁图像。我从一个 PNG 文件开始,其中有一个带圆角的半透明正方形:
然后,我创建了 9-patch,如下所示(注意顶部和左侧的小点):
我认为这足以处理这个问题,但是当将这个 9 补丁添加到 Eclipse 时,我得到了奇怪的结果。
结果编号 1
基于此 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/taxibg3"
android:orientation="vertical" >
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/login_square" />
</LinearLayout>
我得到这个结果:
结果编号 2
基于此 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/taxibg3"
android:orientation="vertical" >
<ImageView
android:layout_width="300dp"
android:layout_height="158dp"
android:background="@drawable/login_square" />
</LinearLayout>
我得到这个结果:
我还尝试使顶部和左侧的“9-patch-lines”更长,但这也会产生奇怪的 Artifact 。
有什么想法吗?
-- 编辑 --
我也尝试过这个 9-patch(来自 9patch-tool 的屏幕截图):
这给出了这个糟糕的结果(注意黑线):
---- 编辑 2 ----
Leonidos 告诉我 9 block 太大了,而且它们无法缩小。所以我尝试了一下,结果同样糟糕。
这是 9 补丁(下载文件 here )
这就是它的样子(注意黑线):
--- 编辑 3 ---
我查看了pathtoo中的“显示坏补丁”,这就是显示的内容:
但这并不重要。如果我改变它,它看起来像这样:
我仍然得到黑色条纹!
哦为什么哦为什么!? =)
最佳答案
让它尽可能小。 9 片不能收缩,但可以拉伸(stretch)。用黑色填充右边框和下边框。使用draw9patch工具编辑9 block 边框以防止错误。您的 9 补丁应该类似于 this one .
关于android - 9 补丁可绘制行为糟糕,奇怪的 Artifact - 这里出了什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14270042/