9 个补丁图像作为背景的问题

发布于 2024-10-18 09:50:06 字数 885 浏览 7 评论 0原文

我有一个列表视图结构,具有使用的相对布局 奇数/偶数元素交替背景图像。我正在尝试设置 通过计算位置动态绘制背景。它 与普通位图一起工作得很好。但是当我尝试使用 ninepatch 图像它破坏了用户界面,所有元素都扭曲了。什么 我做错了吗?这可能是 ninepatch 图像的创建方式或者是 与普通图像相比,有一种不同的方法来使用九块图像 位图。

我的列表视图 XML 是这样的 可能

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content" android:id="@+id/id01"
       android:background="@drawable/my_9patch_bg_image">
       <ImageView  />
       <RelativeLayout>
         <ImageView  />
          <TextView  />
          <TextView  />
       </RelativeLayout>
</RelativeLayout>

​​这里的解决方案可能有效对于我的问题。虽然我必须尝试一下,但它是准确的。

I have a list view structure, with Relative layout that uses
alternating background images for odd/even elements. I'm trying to set
the background drawable dynamically by calculating the position. It
worked fine with the normal bitmap. But when I tried to use the
ninepatch image it breaks the UI, all the elements get distorted. What
am I doing wrong? Could it be how the ninepatch image is created or is
there a different way to use a ninepatch image compared to a normal
bitmap.

My List View XML goes like this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content" android:id="@+id/id01"
       android:background="@drawable/my_9patch_bg_image">
       <ImageView  />
       <RelativeLayout>
         <ImageView  />
          <TextView  />
          <TextView  />
       </RelativeLayout>
</RelativeLayout>

May be the solution here might work for my problem. It's exact though I have to try it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

偏闹i 2024-10-25 09:50:06

已经一年没有人回复你了...
我遇到了同样的问题,您需要将填充设置为零(即使您不需要它)。

祝你好运。

Since nobody answered you for a year now...
I had the same issue you need to setpadding of zero (even if you don't need it).

Good luck.

何必那么矫情 2024-10-25 09:50:06

您可以像使用普通绘图一样使用九个补丁。我假设您的 9 补丁本身有问题。在你的 android sdk 的 /tools 目录中,你有draw 9 补丁工具。它将帮助您纠正 9 个补丁可绘制对象并针对不同尺寸的视图进行预览。

You can use nine patch in the same way you use a normal drawable. I assume you have a problem with the 9 patch itself. In the /tools directory of your android sdk you have the draw 9 patch tool. It will help you to correct your 9 patch drawable and to preview it for different sizes of your view.

北风几吹夏 2024-10-25 09:50:06

选择除角之外的所有边作为拉伸边

select all sides except corners as the stretching edges

自我难过 2024-10-25 09:50:06

您可以使用此 xml 作为背景来显示为卡片视图。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:dither="true" android:shape="rectangle">
        <corners android:radius="2dp" />
        <solid android:color="#e2e2e2" />
    </shape>
</item>
<item android:bottom="2dp">
    <shape android:dither="true" android:shape="rectangle">
        <corners android:radius="2dp" />
        <solid android:color="@color/white" />
    </shape>
</item>

you can use this xml as background to show as cardview.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:dither="true" android:shape="rectangle">
        <corners android:radius="2dp" />
        <solid android:color="#e2e2e2" />
    </shape>
</item>
<item android:bottom="2dp">
    <shape android:dither="true" android:shape="rectangle">
        <corners android:radius="2dp" />
        <solid android:color="@color/white" />
    </shape>
</item>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文