Flex:如何制作进度条皮肤?

发布于 2024-09-25 06:07:41 字数 283 浏览 4 评论 0原文

我想在进度条上设置自定义皮肤,但它没有按照我想要的方式工作。我的皮肤有 3 种不同的颜色(绿色、黄色、红色),绿色应该显示到大约 50%,然后我希望黄色在绿色之后出现,红色在绿色和黄色之后出现 90%。所以在 100% 的情况下,它们应该全部显示出来。

问题是 ProgressBar 仅设置我的皮肤宽度,因此所有颜色始终显示。但是,如果我使用 inminatedSkin 但不将 infinate 设置为 true,则不会发生这种情况。

如何制作不只改变宽度的皮肤? Atm 我只是使用 MovieClip 作为皮肤。

I wanna set a custom skin on my progressBar, but it's not working out the way I want it to. My skin has 3 different colors on it (green, yellow, red) and green should show until it's about 50%, then I want the yellow to appear after green and the red at 90% after green and yellow. So at 100% they should all show.

The problem is that the ProgressBar only sets the width of my skin so all colors are showing at all times. But if I use the indeterminateSkin but dont set indeterminate to true that doesn't happend.

How can I make a skin that doesn't just change width? Atm I'm just using a MovieClip for a skin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看轻我的陪伴 2024-10-02 06:07:41

我过去曾使用程序化皮肤完成此操作。您需要创建自己版本的 ProgressBarSkin 和 ProgressBarMaskSkin 以及可选的 ProgressBarTrackSkin。在您的 ProgressBarSkin 中,您可以像这样覆盖 updateDisplayList 方法:

    override protected function updateDisplayList(w:Number, h:Number):void {
        super.updateDisplayList(w, h);
        graphics.clear();

        var fullWidth:int = w;
        if (parent != null && (parent as UIComponent).mask != null)
            fullWidth = (parent as UIComponent).mask.width;

        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(fullWidth, h);
        var colors:Array = [0xd00000, 0xf0d000, 0x00ff00];

        this.graphics.lineStyle();
        this.graphics.beginGradientFill(GradientType.LINEAR, colors, [1,1,1], [0,128,255], matrix); 
        this.graphics.drawRoundRect(2, 2, w - 4, h - 4, h - 4); 
    }

在您的 ProgressBarMaskSkin 中执行以下操作:

    override protected function updateDisplayList(w:Number, h:Number):void {
        super.updateDisplayList(w, h);
        graphics.clear();

        this.drawRoundRect(2, 2, w - 4, h - 4, (h - 4) / 2, 0xffffff, 1); 
    }

然后将您的外观类分配给进度栏并进行设置。希望有帮助。

I've done this in the past using programmatic skins. You need to create your own versions of ProgressBarSkin and ProgressBarMaskSkin and optionally ProgressBarTrackSkin. In your ProgressBarSkin, you can override the updateDisplayList method like so:

    override protected function updateDisplayList(w:Number, h:Number):void {
        super.updateDisplayList(w, h);
        graphics.clear();

        var fullWidth:int = w;
        if (parent != null && (parent as UIComponent).mask != null)
            fullWidth = (parent as UIComponent).mask.width;

        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(fullWidth, h);
        var colors:Array = [0xd00000, 0xf0d000, 0x00ff00];

        this.graphics.lineStyle();
        this.graphics.beginGradientFill(GradientType.LINEAR, colors, [1,1,1], [0,128,255], matrix); 
        this.graphics.drawRoundRect(2, 2, w - 4, h - 4, h - 4); 
    }

And in your ProgressBarMaskSkin do this:

    override protected function updateDisplayList(w:Number, h:Number):void {
        super.updateDisplayList(w, h);
        graphics.clear();

        this.drawRoundRect(2, 2, w - 4, h - 4, (h - 4) / 2, 0xffffff, 1); 
    }

Then you assign your skin classes to your progress bar and you are set. Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文