是否可以在LayerDrawable中使用多个9补丁图像?

发布于 2024-11-08 16:18:39 字数 637 浏览 5 评论 0原文

我想在 LayerDrawable 中使用两个九个补丁

   <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:id="@+id/solid">
           <nine-patch android:src="@drawable/button_header_solid" android:dither="true" />
       </item>
       <item android:id="@+id/transparent">
           <nine-patch android:src="@drawable/button_header_transparent" android:dither="true" />
       </item>
   </layer-list>

,似乎只有第一层被拉伸,而第二层保持原样。

两个图像的大小都与 .png 相同,并且具有相同的可拉伸区域和填充区域。

问题是:我们是否允许使用多个 9 补丁(在一个图层列表中)还是只允许使用一个?

谢谢。

I want to use two nine patches inside LayerDrawable

   <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:id="@+id/solid">
           <nine-patch android:src="@drawable/button_header_solid" android:dither="true" />
       </item>
       <item android:id="@+id/transparent">
           <nine-patch android:src="@drawable/button_header_transparent" android:dither="true" />
       </item>
   </layer-list>

And it seems that only first layer is stretched while second one stays as is.

Both images are of the same size as .png, and have equal stretchable and padding areas.

The question is: Do we allowed to use several 9-patches (in one layer-list) or only one is allowed?

Thanks.

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

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

发布评论

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

评论(2

删除会话 2024-11-15 16:18:39

刚刚面临同样的问题。
试试这个:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:id="@+id/solid">
           <nine-patch android:src="@drawable/button_header_solid" android:dither="true" />
       </item>
       <item android:id="@+id/transparent">
           <clip>
              <nine-patch android:src="@drawable/button_header_transparent" android:dither="true" />
           </clip>
       </item>
   </layer-list>

Just now faced with the same problem.
Try this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:id="@+id/solid">
           <nine-patch android:src="@drawable/button_header_solid" android:dither="true" />
       </item>
       <item android:id="@+id/transparent">
           <clip>
              <nine-patch android:src="@drawable/button_header_transparent" android:dither="true" />
           </clip>
       </item>
   </layer-list>
一瞬间的火花 2024-11-15 16:18:39

以下内容使两个 9 补丁的行为符合您的预期(在 Android 2.2 上测试)。两个 9 块都被扩展以填充整个可绘制区域。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/solid" 
        android:drawable="@drawable/button_header_solid"/>
    <item android:id="@+id/transparent" 
        android:drawable="@drawable/button_header_transparent"/>
</layer-list>

The following makes both 9-patches behave as you would expect (tested on Android 2.2). Both 9-patches are expanded to fill the whole drawable area.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/solid" 
        android:drawable="@drawable/button_header_solid"/>
    <item android:id="@+id/transparent" 
        android:drawable="@drawable/button_header_transparent"/>
</layer-list>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文