android ImageView 加边框, 加阴影,shadow
比较简单的办法,效果比较丑陋,同理,你可以用阴影图片替代画线得到好的效果重写ImageViewpublic class HKImageView extends ImageView {public HKImageView(Context context, AttributeSet attrs) {super(context, attrs, 0);}public HKImageView(Context context) {super(context);}@Overrideprotected void onDraw(Canvas canvas) {Log.d("lg", "onDraw");super.onDraw(canvas);// 画边框Rect rect1 = getRect(canvas);Paint paint = new Paint();paint.setColor(Color.GRAY);paint.setStyle(Paint.Style.STROKE);// 画边框canvas.drawRect(rect1, paint);paint.setColor(Color.LTGRAY);// 画一条竖线,模拟右边的阴影canvas.drawLine(rect1.right + 1, rect1.top + 2, rect1.right + 1,rect1.bottom + 2, paint);// 画一条横线,模拟下边的阴影canvas.drawLine(rect1.left + 2, rect1.bottom + 1, rect1.right + 2,rect1.bottom + 1, paint);// 画一条竖线,模拟右边的阴影canvas.drawLine(rect1.right + 2, rect1.top + 3, rect1.right + 2,rect1.bottom + 3, paint);// 画一条横线,模拟下边的阴影canvas.drawLine(rect1.left + 3, rect1.bottom + 2, rect1.right + 3,rect1.bottom + 2, paint);}Rect getRect(Canvas canvas) {Rect rect = canvas.getClipBounds();rect.bottom -= getPaddingBottom();rect.right -= getPaddingRight();rect.left += getPaddingLeft();rect.top += getPaddingTop();return rect;}}使用要给图片添加padding才有效果imageView.setPadding(3, 3, 5, 5);