Adobe Air应用程序中的转角半径

时间:2008-11-11 04:51:09

标签: flex air

我们如何在空中的vbox控件上制作圆角 应用

我隐藏了标题并将透明设置为true,但之后它没有显示 我在应用程序中的VBox上圆角。我正在展示这个VBox 给用户。

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以通过实施自定义边框来执行此操作:

package your.package
{

  import flash.display.*;
  import flash.geom.*;
  import flash.utils.*;

  import mx.skins.halo.HaloBorder;
  import mx.utils.GraphicsUtil;

  public class RoundedBorder extends HaloBorder 
  {

    private var topCornerRadius:Number;
    private var bottomCornerRadius:Number;
    private var setup:Boolean;

    /**
     * Get the CSS style attributes from the element to which to apply this
     * gradient. 
     */
    private function readElementCssStyles():void
    {
      topCornerRadius = getStyle("cornerRadius") as Number;
      if (!topCornerRadius)
      { 
        topCornerRadius = 0;
      }    

      bottomCornerRadius = getStyle("bottomCornerRadius") as Number;
      if (!bottomCornerRadius) 
      {
        bottomCornerRadius = topCornerRadius;
      }  
    }

    /**
     * Paint the gradient background.
     *  
     * @param unscaledWidth
     * @param unscaledHeight
     * 
     */
    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
      super.updateDisplayList(unscaledWidth, unscaledHeight);   
      var rectWidth:Number 
          = unscaledWidth - this.borderMetrics.left - this.borderMetrics.right;
      var rectHeight:Number 
          = unscaledHeight - this.borderMetrics.top - this.borderMetrics.bottom; 

      readElementCssStyles();

      var topRadius:Number = Math.max(topCornerRadius-2, 0);
      var bottomRadius:Number = Math.max(bottomCornerRadius-2, 0);

      GraphicsUtil.drawRoundRectComplex(this.graphics, 
                                        this.borderMetrics.left, 
                                        this.borderMetrics.top, 
                                        rectWidth, 
                                        rectHeight, 
                                        topRadius, 
                                        topRadius, 
                                        bottomRadius, 
                                        bottomRadius);
    }

  }
}

然后在您的MXML应用程序中,您必须为您的VBox定义一个CSS类,如下所示:

  <mx:Style>
    .roundedBorder
    {
      border-style:solid;
      border-thickness: 1;
      border-skin: ClassReference("your.package.RoundedBorder");
      corner-radius: 5;
    }   
  </mx:Style>

我已将这段代码从更复杂的类中删除。希望我没有忘记任何事情,它会像发布的那样发挥作用。