Android最简单的Imageview加边框的方法

来源:互联网 发布:python字符串转二进制 编辑:程序博客网 时间:2024/06/05 11:27


只需要在你的drawable中建立一个名bg-border的资源文件即可

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#EEEEEE" />
    <stroke android:width="3dp" android:color="#EEEEEE" />
    <corners android:radius="0dp" />
    <padding android:left="0dp" android:top="0dp"
        android:right="0dp" android:bottom="0dp" />
</shape>

 

在Imageview定义页面上使用代码:

 <ImageView
        android:id="@+id/img"
        android:background="@drawable/bg_border"
        android:src="@mipmap/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />