rek*_*ire 56 android xml-drawable layer-list android-drawable
我不明白图层列表是如何工作的.我通过一些例子阅读了官方文档,但它并不像我预期的那样适用于我.我想要四个正方形,应该用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>
Run Code Online (Sandbox Code Playgroud)
And*_*lly 101
左,上,右和下的值是从它们各自的边缘测量的.
所以left = 0dp,top = 0dp,bottom = 0dp&right = 50dp会给你一个矩形(match_parent - 50dp)宽而不是50dp宽.因此,"right"的较大值实际上会为您提供一个较小的矩形.
这同样适用于另一个值,但在大多数情况下,这些行为会如预期的那样,它只是"正确",可能会引起混淆.
您可以使用px
代替dp
或乘以所有维度10
.
我很惭愧地承认我并不确切知道为什么会发生这种情况,但我的猜测是它与密度有关,其中1dp
浮动px
值ImageView
是按比例放大的.
欢迎专家解答:)
归档时间: |
|
查看次数: |
87011 次 |
最近记录: |