android中xml文件实现带边框背景

作者: 奔跑的佩恩 | 来源:发表于2017-06-22 09:09 被阅读257次

    项目开发的过程中,有时我们会用到带边框的纯色背景图,类似效果如下:

    2.png

    一般的,我们会让设计给做个背景图,然后自己用.9处理一下,这样有些麻烦,我们可以简洁点实现,就是用xml文件,下面给出一个范例:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:right="0dp">
            <shape android:shape="rectangle" >
                <solid android:color="#f9e284"></solid>
            </shape>
        </item>
        <item
            android:right="8dp"
            android:top="8dp"
            android:left="8dp"
            android:bottom="8dp">
            <shape android:shape="rectangle" >
                <stroke
                    android:color="@color/white"
                    android:width="1dp"/>
            </shape>
        </item>
    </layer-list>
    

    颜色,圆角什么的,大家可以自己设置下。

    就到这里了,不是很难,仅作记录,谢谢诶。

    相关文章

      网友评论

        本文标题:android中xml文件实现带边框背景

        本文链接:https://www.haomeiwen.com/subject/nxvxcxtx.html