Aj08:
画面の中央に透明曲がった透明の四角形を作成する方法?
私は、次のコードを書かれており、画面中央部の湾曲した矩形のアルファを加えたが、背景色ではなく、透明度の図示されています
int width = canvas.getWidth();
int height = canvas.getHeight();
Rect childRect = this.getChildRect();
Paint outerPaint = new Paint();
outerPaint.setColor(Color.LTGRAY);
borderPaint.setStyle(Paint.Style.FILL);
Paint innerPaint = new Paint();
innerPaint.setARGB(0, 0, 0, 0);
innerPaint.setAlpha(0);
innerPaint.setStyle(Paint.Style.FILL);
canvas.drawRect(0.0F, 0.0F, width, height, outerPaint);
canvas.drawRoundRect(new RectF(childRect.left, childRect.top, childRect.right, childRect.bottom), 8F, 8F, innerPaint);
Arshak:
あなたはを利用することができるsetXfermode()
の ペイント と合格 PorterDuff.Mode.ADD
と PorterDuff.Mode.ADD
内側の透明度域の代わりに、塗料にアルファを加えることを得るために、パラメータとして。
あなたのコード内で次のように変更します。
int width = canvas.getWidth();
int height = canvas.getHeight();
Rect childRect = this.getChildRect();
Paint outerPaint = new Paint();
outerPaint.setColor(Color.LTGRAY);
outerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD));
outerPaint.setAntiAlias(true);
Paint innerPaint = new Paint();
innerPaint.setColor(Color.TRANSPARENT);
innerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
innerPaint.setAntiAlias(true);
canvas.drawRect(0.0F, 0.0F, width, height, outerPaint);
canvas.drawRoundRect(new RectF(childRect.left, childRect.top, childRect.right, childRect.bottom), 8F, 8F, innerPaint);