【发布时间】:2013-01-04 09:21:17
【问题描述】:
我不明白图层列表是如何工作的。我阅读了官方documentation with some examples,但它并不像预期的那样对我有用。我想要四个应该用 1dp 填充的正方形,但没有什么像预期的那样。这是一个放大 500% 的屏幕截图:
(颜色不对也没关系)
如您所见,大小完全错误,并且缺少填充。我尝试设置真正的值,如宽度/高度和右/左/上/按钮,以确保 android 得到我想要的。
这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="0dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
<shape android:shape="rectangle">
<size android:width="9dp"
android:height="9dp"/>
<solid android:color="#f000"/>
</shape>
</item>
<item android:top="1dp" android:left="1dp" android:bottom="5dp" android:right="5dp">
<shape android:shape="rectangle">
<size android:width="3dp"
android:height="3dp"/>
<solid android:color="#f00"/>
</shape>
</item>
<item android:top="1dp" android:left="5dp" android:bottom="5dp" android:right="1dp">
<shape android:shape="rectangle">
<size android:width="3dp"
android:height="3dp"/>
<solid android:color="#0f0"/>
</shape>
</item>
<item android:top="5dp" android:left="1dp" android:bottom="1dp" android:right="5dp">
<shape android:shape="rectangle">
<size android:width="3dp"
android:height="3dp"/>
<solid android:color="#0f0"/>
</shape>
</item>
<item android:top="5dp" android:left="5dp" android:bottom="1dp" android:right="1dp">
<shape android:shape="rectangle">
<size android:width="3dp"
android:height="3dp"/>
<solid android:color="#f00"/>
</shape>
</item>
</layer-list>
【问题讨论】:
-
你是怎么截屏的?因为它给我的图像看起来绝对正确......
-
我从 eclipse 中获取了可视化编辑器。
-
@rekire 编辑器有问题,所以你知道,它并不总是显示正确的形状。始终检查设备。
标签: android xml-drawable android-drawable layer-list