2012-03-29 6 views
2

Ich habe Button und Im Füllung Button Farbe mit onDraw und Leinwand .. Angenommen, meine Button-Parameter (Links, Oben, Rechts, Unten) sind (0.für den Teil) (20,20,180,180) ich möchte diesen Teil transparent und anderen Teil mit Farbverlauf ..Füllen transparent im Schnittpunkt von RectF Android

enter image description here

@Override 
      protected void onDraw(Canvas canvas) { 
       // TODO Auto-generated method stub 
       super.onDraw(canvas); 
       int[] iColor = { 
         CommonFunctions 
           .getLightColor(bAppointments.getSrtStatus(), 255), 
         CommonFunctions.getColor(bAppointments.getSrtStatus(), 255) }; 

       int[] gapColor = { Color.argb(255, 255, 255, 255), 
         Color.argb(255, 255, 255, 255) }; 

       float[] iPos = { 
         0, 
         (canvas.getClipBounds().bottom - canvas.getClipBounds().top)/2 }; 

       LinearGradient lGradient = new LinearGradient(
         canvas.getClipBounds().right - canvas.getClipBounds().left, 
         canvas.getClipBounds().top, canvas.getClipBounds().right 
           - canvas.getClipBounds().left, 
         canvas.getClipBounds().bottom, iColor, iPos, 
         Shader.TileMode.CLAMP); 

    mPaint.setAlpha(0xBB); 
       mPaint.setShader(lGradient); 
       mPaint.setStyle(Style.FILL); 
    mRectF.set(canvas.getClipBounds().left + 2, 
         canvas.getClipBounds().top + 2, 
         canvas.getClipBounds().right - 2, 
         canvas.getClipBounds().bottom - 6); 
       canvas.drawRoundRect(mRectF, rectCurve, rectCurve, mPaint); 
} 

Derzeit mein Layout aussehen wie

enter image description here

+0

was ist das Problem ...? und besser ist es, es in xml zu tun .. einfach und nicht viel zur Laufzeit zu tun .. – ngesh

+0

@sandy http://i.stack.imgur.com/sItBz.png in diesem .. Ich will den weißen Teil sein transparent, dass es RelativeLayout Color anstelle von Button's Color zeigen muss ... n Ich muss es tun, Zeit zu laufen, da der Farbverlauf auf Logic basiert und nicht statisch ist. –

Antwort

0

für now..I es vorübergehende Lösung mit getan hat .. ich zum ersten Mal transparent für die Schaltfläche gefüllt .. dann geteilt ich den Knopf Leinwand in 5 Teil ..

Top Teil, linker Teil, Gap Teil, rechts Teil und Unterteil .. n I gefüllt, dass ein Teil-Objekt mit dem gleichen Farbe ..

noch für die gute Lösung warten ..

Dank.

Verwandte Themen