首先看一下,下端代码
private Bitmap createSelectedChip(RecipientEntry contact, TextPaint paint) { int height = (int) mChipHeight; int deleteWidth = height; float[] widths = new float[1]; paint.getTextWidths(" ", widths); CharSequence ellipsizedText = ellipsizeText(createChipDisplayText(contact), paint, calculateAvailableWidth() - deleteWidth - widths[0]); printDebugLog(TAG,"[createSelectedChip] " + ellipsizedText); int width = Math.max( 0 /*deleteWidth * 2*/, (int) Math.floor(paint.measureText(ellipsizedText, 0, ellipsizedText.length())) + (mChipPadding * 2) + deleteWidth); /// @} // Create the background of the chip. Bitmap tmpBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(tmpBitmap); if (mChipBackgroundPressed != null) { Rect backgroundPadding = new Rect(); mChipBackgroundPressed.getPadding(backgroundPadding); mChipBackgroundPressed.setBounds(0, 0, width - deleteWidth, height); mChipBackgroundPressed.draw(canvas); paint.setColor(sSelectedTextColor); canvas.drawText(ellipsizedText, 0, ellipsizedText.length(), mChipPadding, getTextYOffset((String) ellipsizedText, paint, height), paint); mChipDelete.setBounds(width - deleteWidth - backgroundPadding.left, 0 + backgroundPadding.top/2, width - backgroundPadding.right/2, height); mChipDelete.draw(canvas); } else { Log.w(TAG, "Unable to draw a background for the chips as it was never set"); } return tmpBitmap; }
如
Drawable drawable = xxxx; drawable.setBounds(int, int, int, int); drawable.draw(canvas);
setBounds 有人给出的解释是,绘制图片时候,相对于父容器的边距
但是,通过验证,我感觉应该是如下的解释,看图
原文:http://www.cnblogs.com/zhangshuli-1989/p/4362195.html