У меня есть настроенная кнопка, и я заполняю цвет кнопки, используя onDraw и Canvas. Предположим, мои параметры кнопки (слева, сверху, справа, снизу) равны (0,0,200,200), а затем для части (20,20,180,180). Я хочу эту частьпрозрачная и другая часть с градиентным цветом ..
@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);
}
В настоящее время мой макет выглядит как