专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > BlackBerry

blackberry中, 创造用渐变色填充的圆角矩形背景

发布时间:2010-05-30 19:38:34 文章来源:www.iduyao.cn 采编人员:星星草
blackberry中, 创建用渐变色填充的圆角矩形背景
创建用渐变色填充的圆角矩形背景
http://yy629.iteye.com 344850459 日期: 2010-07-22


这几天一直在学习blackberry开发, 记录一些有用的代码, 免得忘记了..

在blackberry中, 默认创建的渐变色背景都是矩形的, 有时我们需要绘制圆角矩形的渐变色背景, 所以就自己定义一个工厂类, 用来创建特殊的渐变色背景

代码如下

/**
 * @author YeYong
 * @date 2010-7-21 PM10:42:46
 */
public class SfBackgroundFactory {

  /**
   * 创建渐变色的圆角矩形背景
   * @param colorTopLeft - Starting color at top-left corner of background.
   * @param colorTopRight - Starting color at top-right corner of background.
   * @param colorBottomRight - Starting color at bottom-right corner of background.
   * @param colorBottomLeft - Starting color at bottom-left corner of background. 
   * @param arcWidth Width of arc used to round the four corners.
   * @param arcHeight Height of arc used to round the four corners.
   * @return
   */
  public static Background createLinearGradientRoundBackground(final int colorTopLeft,
      final int colorTopRight, final int colorBottomRight, final int colorBottomLeft, 
      final int arcWidth, final int arcHeight) {
    final Background bg = BackgroundFactory.createLinearGradientBackground(colorTopLeft, 
        colorTopRight, colorBottomRight, colorBottomLeft);
    return new Background() {
      public boolean isTransparent() {
        return bg.isTransparent();
      }

      public void draw(Graphics g, XYRect xyRect) {
        int width = xyRect.width;
        int height = xyRect.height;
        XYRect rect = new XYRect(0, 0, width, height);

        Bitmap bg1 = new Bitmap(width, height);
        Graphics g2 = Graphics.create(bg1);
        BackgroundFactory.createLinearGradientBackground(colorTopLeft, colorTopRight,
            colorBottomRight, colorBottomLeft).draw(g2, rect);

        Bitmap bg2 = new Bitmap(width, height);
        Graphics g3 = Graphics.create(bg2);
        g3.setColor(Color.BLACK);
        g3.fillRoundRect(0, 0, width, height, arcWidth, arcHeight);
        g3.rop(Graphics.ROP2_DSo, 0, 0, width, height, bg1, 0, 0);

        g.setColor(Color.WHITE);
        g.fillRoundRect(xyRect.x, xyRect.y, width, height, arcWidth, arcHeight);

        g.rop(Graphics.ROP2_DSa, xyRect.x, xyRect.y, width, height, bg2, 0, 0);
      }
    };
  }
}


效果图如下:

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: