通过Android 中自定义的属性给ImageView设置上下左右边框,请参照下面的代码,同样是在drawable文件夹下创建shape类型的xml文件,比如:img_border.xml,然后在该文件中添加如下代码,同样是通过android:background=”@drawable/img_border”来引用,两篇最基础的样式,方便自己查看吧。代码区如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- This is the main color 主要用于给view设置上下边框 -->
<item>
<shape>
<!-- 边框颜色 -->
<solid android:color="@color/back_bottom"/>
</shape>
</item>
<!-- 给View的上 左 右 下设置边框 ,其中只有底部边框是6dp,其他边框都为0-->
<item android:top="0dp" android:left="0dp" android:right="0dp" android:bottom="6dp" >
<shape>
<!-- View填充颜色 -->
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>