我可以用一个机器人绘制使用多个形状?多个、可以用、机器人、形状

2023-09-13 01:51:50 作者:胸怀天下不老人

我想要做的是在LinearLayout中其中流连我的应用程序在它的许多Activitys定义一个共同的背景使用。这个特定的布局是一个首标,显示在每个活动的顶部。

我想要做的就是创建一个可绘制,填补了的LinearLayout的梯度,并具有一个水平线上的梯度之下。

有谁知道这是可能的或做我必须做这样的事情只能用嵌套布局。

谢谢

我attemptat可绘制的XML是

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目>
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:形状=矩形>
    <梯度安卓startColor =#AA000000机器人:endColor =#AA333333
        机器人:角=270/>
< /形状>
< /项目>
<项目>
<形机器人:形状=行>
    <行程机器人:宽=3DP机器人:颜色=#FFFFFFFF
            机器人:dashWidth =1DP机器人:dashGap =2DP/>
    <大小机器人:身高=5DP/>
< /形状>
< /项目>
< /选择器>
 

解决方案

绘制对象接受多个形状,(在其他文件总是定义),如果我明白你的问题,也许你可以做一个图层绘制(由此得出多个基本可绘之上对方)

我写这篇文章在这里,所以,我没有测试过,但这种尝试并阅读这美妙的文档。

 < XML版本=1.0编码=UTF-8&GT?;
    <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        <项目机器人:可绘制=@可绘制/ shape_7/>
        <项目机器人:可绘制=@可绘制/ shape_1/>
    < /层列表>
 

Android的完整的XML资源

欢呼声

如何绘制机器人的姿势

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.

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.

Thanks,

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

the android complete xml resources

cheers