android - 9 补丁可绘制行为糟糕,奇怪的 Artifact - 这里出了什么问题?

标签 android android-layout nine-patch

所以我正在尝试 9 补丁图像。我从一个 PNG 文件开始,其中有一个带圆角的半透明正方形:

enter image description here

然后,我创建了 9-patch,如下所示(注意顶部和左侧的小点):

enter image description here

我认为这足以处理这个问题,但是当将这个 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>

我得到这个结果:

enter image description here

结果编号 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>

我得到这个结果:

enter image description here

我还尝试使顶部和左侧的“9-patch-lines”更长,但这也会产生奇怪的 Artifact 。

有什么想法吗?

-- 编辑 --

我也尝试过这个 9-patch(来自 9patch-tool 的屏幕截图):

enter image description here

这给出了这个糟糕的结果(注意黑线):

enter image description here

---- 编辑 2 ----

Leonidos 告诉我 9 block 太大了,而且它们无法缩小。所以我尝试了一下,结果同样糟糕。

这是 9 补丁(下载文件 here )

enter image description here

这就是它的样子(注意黑线):

enter image description here

--- 编辑 3 ---

我查看了pathtoo中的“显示坏补丁”,这就是显示的内容:

enter image description here

但这并不重要。如果我改变它,它看起来像这样:

enter image description here

我仍然得到黑色条纹!

哦为什么哦为什么!? =)

最佳答案

让它尽可能小。 9 片不能收缩,但可以拉伸(stretch)。用黑色填充右边框和下边框。使用draw9patch工具编辑9 block 边框以防止错误。您的 9 补丁应该类似于 this one .

关于android - 9 补丁可绘制行为糟糕,奇怪的 Artifact - 这里出了什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14270042/

相关文章:

android - 如何创建 9-patch 并在我的应用程序中使用它?

Android 尝试读取已关闭的流错误?

java - 使用 getResources().openRawResource() 时有没有办法避免大小限制

android - 按钮 layout_height=线性布局内的 wrap_content 高度比 wrap_content 大得多

java - 9-patch 文件中出现奇怪的黑边 - android

android 9-patch 渐变

javascript - HTML5 GeoLocation 不适用于 Android

android - 绘制具有特定文本外观的文本

android - 旋转屏幕后找不到微调器

android - 在消息 block 中显示时间