我正在尝试为具有多个渐变的线性布局创建背景可绘制。
E.g。我希望在顶部和底部有一个渐变,在中间有一个纯色。所以基本上是一个页眉和页脚。
我正在尝试使用这样的图层列表:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<!--Red-->
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#ff0000" />
</shape>
</item>
<!-- Green -->
<!-- Offsets from the top and bottom -->
<item
android:top="20dp"
android:bottom="20dp">
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#00ff00" />
</shape>
</item>
<item
android:top="80dp">
<!--Blue -->
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#0000ff" />
</shape>
</item>
</layer-list>
问题是,我不确定密度独立像素的最大值。为了实现这一点,最底层的项目需要是(最大dp值-20)。我试图假设max是100,并且还假设max是160(来自文档),但这些都不起作用。
有什么想法吗?