Can I use multiple shapes in one Android drawable?

99封情书 提交于 2019-11-29 05:35:47
Franco

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

Use gravity to set your items in layer-list.

    for vertical orientation use:
    android:gravity="top"
    android:gravity="center"
    android:gravity="bottom"
    for horizontal orientation use:
    android:gravity="left"
    android:gravity="center"
    android:gravity="right"
<layer-list
           xmlns:android="http://schemas.android.com/apk/res/android">
          <item>
                <bitmap
                   android:src="@drawable/top_img"
                   android:gravity="top"/>
          </item>
          <item>
                <bitmap
                   android:src="@drawable/center_img"
                   android:gravity="center"/>
          </item>
          <item>
                <bitmap
                   android:src="@drawable/bottom_img"
                   android:gravity="bottom"/>
          </item>
</layer-list>

Be sure that the parent element has enough space to hold all the items! Otherwise they will overlap each other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!