2016-10-26 13 views
1

Androidのビューの背景矩形を描きたいと思います。ここに私のコードアンドロイドでrectangeの横の線の一部を削除します

rectBox= new RectF(0, 0, 200, 
     200); 
Paint paint= new Paint(); 
paint.setStyle(Paint.Style.STROKE); 
paint.setStrokeWidth(2); 
paint.setColor(Color.BLACK); 
canvas.drawRoundRect(rectBox, 0, 0, paint); 

私は出力

enter image description here

私はこの出力をしたいを取得しています。私は、矩形

enter image description here

のエッジにセグメントの一部を削除したいこれを行う方法のアイデアを教えてください?

答えて

0

そのセグメントに背景色の線(または長方形)を描くだけです。

更新drawLine()drawArc()を使用してちょうど必要な部分を描きます。

+0

私の背景色が動的であるので、我々は、ビューの色を知りません、 –

+0

更新された回答をご覧ください。 –

+0

アンドロイドでは?描画された線を削除するオプションがありますか? –

0

必要な場所に透明な線を描くことができます。

Paint paint = new Paint(); 
paint.setColor(Color.TRANSPARENT); 
canvas.drawLine(0, 8, 0, 15, paint); 
canvas.drawLine(8, 0, 15, 0, paint); 
canvas.drawLine(8, 8, 8, 15, paint); 
canvas.drawLine(15, 8, 15, 15, paint); 
+0

いいえ、私は白い色をしたくない、私は線の部分を削除したい。私は画面の背景色を見たいが、私の画面の背景色は、動的画像です –

+0

私は答えを編集しました。透明な線を描くことができます。 –

+0

これを試してみてください。矩形の色が表示されます –

0

は、私がラウンドコーナーのためにはよく分からないが、ここで私は私のプロジェクトの一つでdonedてる何

public void draw(@NonNull Canvas canvas) { 
    super.draw(canvas); 

     // Full left band 
     canvas.drawRect(0, 0, rect.left, getHeight(), rectPaint); 

     // Full right band 
     canvas.drawRect(rect.right, 0, getWidth(), getHeight(), rectPaint); 

     // Partial top band 
     canvas.drawRect(rect.left, 0, rect.right, rect.top, rectPaint); 

     // Partial bottom band 
     canvas.drawRect(rect.left, rect.bottom, rect.right, getHeight(), rectPaint); 

     // Top lines 
     canvas.drawRect(
       rect.left - strokeWidth, rect.top - strokeWidth, 
       rect.left + cornerLength, rect.top, 
       borderPaint 
     ); 
     canvas.drawRect(
       rect.right - cornerLength, rect.top - strokeWidth, 
       rect.right + strokeWidth, rect.top, 
       borderPaint 
     ); 

     // Bottom lines 
     canvas.drawRect(
       rect.left - strokeWidth, rect.bottom, 
       rect.left + cornerLength, rect.bottom + strokeWidth, 
       borderPaint 
     ); 
     canvas.drawRect(
       rect.right - cornerLength, rect.bottom, 
       rect.right + strokeWidth, rect.bottom + strokeWidth, 
       borderPaint 
     ); 

     // Left lines 
     canvas.drawRect(
       rect.left - strokeWidth, rect.top - strokeWidth, 
       rect.left, rect.top + cornerLength, 
       borderPaint 
     ); 
     canvas.drawRect(
       rect.left - strokeWidth, rect.bottom - cornerLength, 
       rect.left, rect.bottom + strokeWidth, 
       borderPaint 
     ); 

     // Right lines 
     canvas.drawRect(
       rect.right, rect.top - strokeWidth, 
       rect.right + strokeWidth, rect.top + cornerLength, 
       borderPaint 
     ); 
     canvas.drawRect(
       rect.right, rect.bottom - cornerLength, 
       rect.right + strokeWidth, rect.bottom + strokeWidth, 
       borderPaint 
     ); 

} 
関連する問題