一、前言
Android自定义边框,可以设置任意边框的角度和阴影。我下面分为 四个角度设置边框、两个角度设置边框、半圆球设置边框加两层阴影等。
二、边框分类:
1、四个角度设置边框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/dp_16" />
<solid android:color="@color/color_FFFAFAFA" />
</shape>
效果图:
图片.png2、两个角度设置边框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/white" />
<corners
android:topLeftRadius="@dimen/dp_20"
android:topRightRadius="@dimen/dp_20"
/>
<padding
android:top="@dimen/dp_10" />
</shape>
效果图:
图片.png3、半圆球设置边框加两层阴影
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 外层边框1 -->
<item>
<shape>
<padding
android:bottom="@dimen/dp_1"
android:left="@dimen/dp_1"
android:right="0dp"
android:top="@dimen/dp_1" />
<solid android:color="#f00" />
<corners
android:bottomLeftRadius="@dimen/dp_28"
android:topLeftRadius="@dimen/dp_28" />
</shape>
</item>
<!-- 外层边框2 -->
<item>
<shape>
<padding
android:bottom="@dimen/dp_1"
android:left="@dimen/dp_1"
android:right="0dp"
android:top="@dimen/dp_1" />
<solid android:color="@color/color_FFF9F8F8" />
<corners
android:bottomLeftRadius="@dimen/dp_27"
android:topLeftRadius="@dimen/dp_27" />
</shape>
</item>
<!-- 外层边框3 -->
<item>
<shape>
<padding
android:bottom="@dimen/dp_1"
android:left="@dimen/dp_1"
android:right="0dp"
android:top="@dimen/dp_1" />
<solid android:color="@color/color_FFDBDBDB" />
<corners
android:bottomLeftRadius="@dimen/dp_26"
android:topLeftRadius="@dimen/dp_26" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item>
<!-- 边框里面背景颜色 白色 -->
<shape>
<solid android:color="@color/color_FFFFFF" />
<size
android:width="@dimen/dp_52"
android:height="@dimen/dp_52" />
<corners
android:bottomLeftRadius="@dimen/dp_26"
android:topLeftRadius="@dimen/dp_26" />
</shape>
</item>
</layer-list>
效果图:
图片.png 图片.png
网友评论