我使用onDraw和Canvas定制按钮和Im填充按钮颜色.. 假设我的按钮参数(左,上,右,下)是(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);
}
目前我的布局看起来像
答案 0 :(得分:0)
现在..我已经使用临时解决方案完成了.. 我先把按钮透明填充.. 然后我将Button Canvas分为5部分..
顶部,左部,间隙部分,右部和底部.. 我用相同的Paint对象填充了那个部分..
仍在等待好的解决方案..
感谢。