Is it possible to use several 9 patch images inside LayerDrawable?
Asked Answered
G

2

13

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.

Grum answered 21/5, 2011 at 9:34 Comment(0)
W
3

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>
Wiggs answered 29/10, 2011 at 14:44 Comment(1)
@karthi B, edits are not meant to add comments to posts. Besides, StackOverflow is not meant to do your work. If you have a problem, please ask a specific question and read the FAQ.Flicker
T
2

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>
Tereus answered 24/4, 2012 at 23:42 Comment(1)
I found this solution works, but with a couple of nuances: (1) both layers have to be exactly the raw size; (2) the content area of the first layer had to be set to the entire imageBagehot

© 2022 - 2024 — McMap. All rights reserved.