In general, if we want to add a border to the ImageView, such as a gray box with a width of 3dp, we define a MyImageView class, inherit from ImageView, and draw a canvas in its onDraw method. You can also set a background image with a border. Here is a simple method. You do not need to create derivative classes or prepare images. Implemented in xml format. Background definition xml: bg_border.xml <? Xml version = "1.0" encoding = "UTF-8"?> <Shape xmlns: android = "http://schemas.android.com/apk/res/android"> <solid android: color = "# EEEEEE"/> www.2cto.com <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> use the code on the Imageview definition page: <ImageView android: id = "@ + id/iv_thumbnail" android: layout_height = "63dp" android: layout_width = "63dp" android: background = "@ drawable/bg_border" android: padding = "3dp"/>