我可以在一个 Android drawable 中使用多个形状吗? [英] Can I use multiple shapes in one Android drawable?

查看:42
本文介绍了我可以在一个 Android drawable 中使用多个形状吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是定义一个在 LinearLayout 中使用的通用背景,它经常出现在我的应用程序的许多活动中.这个特定的布局是一个显示在每个活动顶部的标题.

What I'm trying to do is define a common background for use in a LinearLayout which frequents my application on many of its Activitys. This particular layout is a header that shows on the top of each activity.

我想要做的是创建一个 drawable,用渐变填充线性布局,并在渐变下方有一条水平线.

What I'm trying to do is create a drawable that fills the linearlayout with a gradient and has a horizontal line below the gradient.

有谁知道这是否可行,或者我是否必须只使用嵌套布局来做这种事情.

Does anyone know if this is possible or do I have to do this sort of thing only with nested layouts.

我对 drawable xml 的尝试是

My attemptat the drawable xml is

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#AA000000" android:endColor="#AA333333"
        android:angle="270" />
</shape>
</item>
<item>
<shape android:shape="line">
    <stroke android:width="3dp" android:color="#FFFFFFFF"
            android:dashWidth="1dp" android:dashGap="2dp" />
    <size android:height="5dp" />
</shape>
</item>
</selector>

推荐答案

Drawable 接受多个形状,(总是在其他文件中定义)如果我理解你的问题,也许你可以做一个 Layer drawable(这会在彼此)

Drawable accepts multiple shapes, (defined always in others files) if i understand your question maybe you can do a Layer drawable (this draws multiple underlying drawables on top of each other)

我在这里写这个,所以,我没有测试,但试试这个并阅读这个很棒的文档.

i write this here, so, i dont tested, but try this and read this fantastic documentation.

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/shape_7"/>
        <item android:drawable="@drawable/shape_1"/>
    </layer-list>

android完整的xml资源

干杯

这篇关于我可以在一个 Android drawable 中使用多个形状吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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