Android,如何制作平滑渐变?

时间:2012-11-18 09:25:45

标签: android

我正在尝试制作一个按钮背景,但它看起来有些锯齿状。

enter image description here

public Bitmap makeButtonBit (int w,int h)
{

    Bitmap bitmapBtn = Bitmap.createBitmap(w, h+2, Bitmap.Config.ARGB_8888);
    Canvas cnvBtn = new Canvas(bitmapBtn);

    Paint pR1 = new Paint();
    pR1.setAntiAlias(true);
    pR1.setAlpha(40);
    ///

    RectF rectShd1 = new RectF(0, 0, w, h+1);
    cnvBtn.drawRoundRect(rectShd1, 8, 8, pR1);

    RectF rectShd2 = new RectF(0, 0, w, h+2);
    cnvBtn.drawRoundRect(rectShd2, 8, 8, pR1);
    ///
    pR1.setAlpha(255);
    pR1.setShader(new LinearGradient(0, 0, 0, h, 0x11000000, 0xCC000000, TileMode.CLAMP));
    RectF rect1 = new RectF(0, 0, w, h);
    cnvBtn.drawRoundRect(rect1, 6, 6, pR1);

    pR1.setShader(new LinearGradient(0, 0, 0, h, 0xFF858990, 0xFF2E3337, TileMode.CLAMP));
    RectF rect2 = new RectF(1, 1, w-1, h-1);
    cnvBtn.drawRoundRect(rect2, 6, 6, pR1);

    pR1.setShader(new LinearGradient(0, 0, 0, h, 0xFF525A63, 0xFF2D343A, TileMode.CLAMP));
    RectF rect3 = new RectF(2, 2, w-2, h-2);
    cnvBtn.drawRoundRect(rect3, 6, 6, pR1);

    return bitmapBtn;
}

任何想法我做错了什么?

感谢。

1 个答案:

答案 0 :(得分:1)

为什么不使用九个补丁?