我无法深入了解安卓如何实现其层列表绘制。但是我觉得这很有趣,我几乎不知道为什么会发生这种情况。
以下是一些可绘制内容:
九宫格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
<?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>
水波纹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>
所有图层都包含在layer-list中。
<?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>
很遗憾,我仍然无法在L预览版上使用截屏功能,但我可以描述一下。
所得到的形状(显然我没有明确设置其尺寸)并没有覆盖整个Nine-Patch。 Nine-Patch未伸展的部分被神奇地视为某种“自动填充物”。 我所期望的是(好吧,我实际上期望的就是Android为我完成的事情,我的意思是...假设...):尺寸不特别大的形状可覆盖整个Nine-Patch,就像后者是普通png文件一样。
但是这个形状确实会神奇地避开Nine-Patch中未拉伸的部分,只覆盖它的拉伸部分。
这太棒了......但令人困惑,为什么?我可能无法深入挖掘源代码,但这听起来反直觉(但很好)。 我想知道原因。所以我在这里发布了这个帖子。
由于我正在使用一个Android L版本,因此我将其标记为android-L。 但我认为从gingerbread开始应该也可以工作。