繁体   English   中英

Android 中的嵌套形状

[英]Nested shapes in Android

我正在尝试绘制一个具有三个矩形形状的形状:

  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的渐变,并在最后添加一条 while 线。

如果您打算考虑使用多个形状,则应该尝试使用 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM