Why does Android layer list look so reasonable?

I cannot deeply understand how android implements its layer list. But I find it interesting and I can't figure out why this is happening.

Here are some examples:

ninth patch xml

<?xml version="1.0" encoding="utf-8"?>
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/cam2tst_ripple_bg_img">
</nine-patch>

      

xml form

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<padding
    android:left="@dimen/cam2tst_ripple_horizontal_padding"
    android:top="@dimen/cam2tst_ripple_vertical_padding"
    android:right="@dimen/cam2tst_ripple_horizontal_padding"
    android:bottom="@dimen/cam2tst_ripple_vertical_padding" />
<solid android:color="@android:color/holo_green_dark" />
</shape>

      

ripple xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/holo_green_light">
<item android:drawable="@drawable/cam2tst_ripple_shape"></item>
</ripple>

      

a list of layers containing all of the above

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/cam2tst_ripple_bg_img" />
<item android:drawable="@drawable/cam2tst_ripple_base" />
</layer-list>

      

Unfortunately I still can't get my screenshot work to work on my L preview, but I can describe it.

What I get is the shape (which didn't explicitly size it) doesn't cover the whole nine patch! The unexpanded part of the nine patches is magically seen as a kind of "what I expected (ok, I expected what exactly android did for me, I mean what I was ... presumably ...) is something not so positive: non-standard coverage of all nine patches, as if the last one was a normal png.

But the shape magically avoids the extended portion of nine patches and overlays only over the extended portion of the nine patches.

This is awesome ... but confusing, why? I may not be able to dig this deep into the source, but it sounds like anti-intuition (but nice). However, I want to know the reason. So I am posting this here.

Since I marked this as android-L because I am working on it. But I think this will work from something like a gingerbread (only to replace the ripples being pulled by something else, perhaps a drop to insert, etc.).

+3


source to share


1 answer


This effect is caused by a combination of two things:

  • All nine-patch drawings have a padding area that is automatically detected around the edges of the content area. The content area can be defined either explicitly using the right and bottom lines on the border, or implicitly from the stretch area defined by the left and top lines.

  • A leaf layer applies padding to each layer cumulatively to the next layer by default * effectively treating each layer as the contents of the previous layer.



* Lollipop introduced a new attribute to disable this behavior.

+6


source







All Articles