Android中的嵌套形状 [英] Nested shapes in Android

查看:180
本文介绍了Android中的嵌套形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to draw a shape that has three rectangular shapes:


  1. 纯色

  2. gradient

  3. 白线

我该怎么做?

当我尝试此操作时,它不起作用。布局具有父级颜色。

When I try this, it does not work. The layout has the parent color.

<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 并在末尾添加一会儿行。

I am trying to make a gradient in 3 colors. Start with a solid color #ff297baf, at 60% start a gradient from #ff297baf to #ff16c0e3 and add a while line at the end.

推荐答案

如果您要查看要使用多种形状,您应该尝试使用LayerListDrawable。像这样的东西对我有用,但仅适用于您的示例高度60px。您可能需要修改它以完全适合您的需求,但这应该为您提供一个良好的开端:

If you're going to look into using multiple shapes, you should try a LayerListDrawable. Something like this works for me, but only for your example height of 60px. You may have to modify it to suit your needs exactly, but this should get you a good start:

<?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>

这篇关于Android中的嵌套形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆