2016-12-01 4 views
1

Je veux dessiner 4 coins au centre de l'appareil en utilisant la toile.Comment dessiner 4 coins Edges centre de l'appareil

Vous aimez cette

enter image description here

J'essaie cette

Paint myPaint = new Paint(); 
myPaint.setColor(Color.GREEN); 
myPaint.setStyle(Paint.Style.STROKE); 
canvas.drawRect(
     getLeft()+(getRight()-getLeft())/4, 
     getTop()+(getBottom()-getTop())/4, 
     getRight()-(getRight()-getLeft())/4, 
     getBottom()-(getBottom()-getTop())/3,myPaint); 

Mon résultat

enter image description here

+3

utilisation [drawPath] (https://developer.android.com/reference/android/graphics/Canvas.html# drawPath (android.graphics.Path, android.graphics.Paint) au lieu de drawRect. – Blackbelt

+1

utiliser le vecteur Dessiné pour cela .. http://stackoverflow.com/a/40217644/6893465 –

+1

... ou un simple 9 patch –

Répondre

0

Je suis tirer cette aide 9 Image Patch ....

Bitmap b= BitmapFactory.decodeResource(getResources(), R.drawable.bg_scanner_frame); 
    paint.setColor(Color.RED); 
    canvas.drawBitmap(b, width/2-b.getWidth()/2, height/2-b.getHeight()/2, paint); 

enter image description here