9 个补丁图像作为背景的问题
我有一个列表视图结构,具有使用的相对布局 奇数/偶数元素交替背景图像。我正在尝试设置 通过计算位置动态绘制背景。它 与普通位图一起工作得很好。但是当我尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
已经一年没有人回复你了...
我遇到了同样的问题,您需要将填充设置为零(即使您不需要它)。
祝你好运。
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.
您可以像使用普通绘图一样使用九个补丁。我假设您的 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.
选择除角之外的所有边作为拉伸边
select all sides except corners as the stretching edges
您可以使用此 xml 作为背景来显示为卡片视图。
you can use this xml as background to show as cardview.