微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android:使用多个形状作为Button背景

如何使用xml中定义的多个形状作为 android中按钮的背景?

假设我有多个形状的xml文件,例如: –

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <solid android:color="#eeffffff" />
    <corners android:bottomrighTradius="8dip"
        android:bottomLefTradius="8dip"  
        android:topRighTradius="8dip"
        android:topLefTradius="8dip"/>
</shape>

我想在按钮背景中使用multishapes: –

<Button
    android:id="@+id/funkyButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:text="@string/txt_higher" 
    android:background="@drawable/funkyShape"/>

我如何组合多个形状最终得到一个像这样的按钮: – ?

解决方法

尝试funkyShape.xml,如:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape android:shape="rectangle">
        <size 
            android:width="100dp"
            android:height="40dp" />
        <solid android:color="#ff0000" />
        <corners android:radius="30dp"/>
    </shape>
</item>

<item
    android:top="10dp"
    android:left="10dp"
    android:right="60dp"
    android:bottom="10dp">
    <rotate
        android:fromdegrees="45"
        android:todegrees="45">
        <shape android:shape="rectangle">
            <solid android:color="#ffff00" />
            <corners android:radius="5dp"/>
        </shape>
    </rotate>
</item>

<item
    android:top="5dp"
    android:left="55dp"
    android:right="5dp"
    android:bottom="5dp">
    <shape android:shape="oval">
        <solid android:color="#0000ff" />
    </shape>
</item>

</layer-list>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐