Android知识Android开发经验谈Android开发

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

2017-06-22  本文已影响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>

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

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

上一篇下一篇

猜你喜欢

热点阅读