答案 0 :(得分:1)
修改
将以下代码放在像DiamondTextView
这样的java类中:
public class DiamondTextView extends TextView{
public DiamondTextView(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
}
Paint mBorderPaint = new Paint();
@Override
protected void onDraw(Canvas canvas) {
mPath.moveTo(mWidth/2 , 0);
mPath.lineTo(mWidth , mHeight/2);
mPath.lineTo(mWidth /2 , mHeight);
mPath.lineTo(0 , mHeight/2);
mPath.lineTo( mWidth/2 ,0);
//setup the paint for fill
mBorderPaint.setAlpha(255);
mBorderPaint.setColor(mBorderColor);
mBorderPaint.setStyle(Paint.Style.FILL);
borderPaint.setStrokeWidth(mBorderWidth);
//draw it
canvas.drawPath(mPath ,mBorderPaint);
//setup the paint for stroke
mBorderPaint.setAlpha(51);
mBorderPaint.setStyle(Paint.Style.STROKE);
//draw it again
canvas.drawPath(mPath ,mBorderPaint);
super.onDraw(canvas);
}
}
并将其称为您要使用此textView的地方:
<com.erginus.ABC.Commons.DiamondTextView...../>
有关详细信息,请查看此处:http://developer.android.com/reference/android/graphics/drawable/shapes/PathShape.html
您也可以使用以下库:https://github.com/siyamed/android-shape-imageview