Android ImageView枠線、シャドウ、shadow

1665 ワード


       ,      ,  ,                  

  ImageView

public class HKImageView extends ImageView {

	public HKImageView(Context context, AttributeSet attrs) {
		super(context, attrs, 0);
	}

	public HKImageView(Context context) {
		super(context);
	}

	@Override
	protected 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);