我试图绘制具有三种矩形形状的形状:
1.纯色2.渐变3.白线
我怎么做?当我尝试一下时,它不起作用。布局具有父颜色。

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:height="60px"
    >
    <shape 
        android:shape="rectangle" 
        android:height="30px"
        >
        <solid 
            android:color="#ff297baf" 
            />
    </shape>
    <shape 
        android:shape="rectangle"
        android:height="30px"
        >
         <gradient
  android:type="linear"
  android:startColor="#ff297baf"
  android:endColor="#ff16c0e3"
  android:angle="270"/> 
    </shape>
    <shape
        android:shape="rectangle"
        android:height="3px"
        >
        <solid 
            android:color="#FFFFFFFF"
            />
    </shape>
</shape>

我试图用3种颜色制作渐变。从纯色开始 #ff297baf, ,60%从 #ff297baf#ff16c0e3 并在最后添加一条线。

有帮助吗?

解决方案

如果您要考虑使用多种形状,则应尝试使用layerListDrawable。这样的东西对我有用,但仅适用于您的60px的示例。您可能必须对其进行修改以完全适合您的需求,但这应该使您有一个良好的开始:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <gradient
            android:angle="270"
            android:endColor="#ff16c0e3"
            android:startColor="#ff297baf"
            android:type="linear" />
    </shape>
</item>
<item android:top="57px">
    <shape android:shape="rectangle">
        <solid android:color="#FFFFFFFF" />
        <size android:height="3px" />
    </shape>
</item>

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top