Back to project page Avatar.
The source code is released under:
GNU General Public License
If you think the Android project Avatar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.syw.avatar.widget; /*from w w w . j a va2s.c om*/ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; /** * ????? * * @author king * @time 2014-6-18 ????3:53:00 */ public class ClipView extends View { /** * ?????????????????????? */ public static final int BORDERDISTANCE = 50; private Paint mPaint; public ClipView(Context context) { this(context, null); } public ClipView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public ClipView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mPaint = new Paint(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int width = this.getWidth(); int height = this.getHeight(); // ?????????????????50px int borderlength = width - BORDERDISTANCE *2; mPaint.setColor(0xaa000000); // ??????????? // top canvas.drawRect(0, 0, width, (height - borderlength) / 2, mPaint); // bottom canvas.drawRect(0, (height + borderlength) / 2, width, height, mPaint); // left canvas.drawRect(0, (height - borderlength) / 2, BORDERDISTANCE, (height + borderlength) / 2, mPaint); // right canvas.drawRect(borderlength + BORDERDISTANCE, (height - borderlength) / 2, width, (height + borderlength) / 2, mPaint); // ??????? mPaint.setColor(Color.WHITE); mPaint.setStrokeWidth(2.0f); // top canvas.drawLine(BORDERDISTANCE, (height - borderlength) / 2, width - BORDERDISTANCE, (height - borderlength) / 2, mPaint); // bottom canvas.drawLine(BORDERDISTANCE, (height + borderlength) / 2, width - BORDERDISTANCE, (height + borderlength) / 2, mPaint); // left canvas.drawLine(BORDERDISTANCE, (height - borderlength) / 2, BORDERDISTANCE, (height + borderlength) / 2, mPaint); // right canvas.drawLine(width - BORDERDISTANCE, (height - borderlength) / 2, width - BORDERDISTANCE, (height + borderlength) / 2, mPaint); } }