如何将 Flex Mobile ActionBar 向下移动一点?

发布于 2024-12-13 11:28:03 字数 1998 浏览 0 评论 0原文

我试图简单地将 actionBar 向下移动 75 像素,这样我就可以在其中挤压 adMob 广告。

我尝试过:

navigator.actionBar.y=75;

但是,我在视觉上没有看到任何不同的东西,它没有移动,它没有给我任何错误,但如果我执行 trace(navigator.actionBar.y); 它声称它处于 75。 ...尽管它显然不在屏幕上。

有人有什么想法吗?另外,这仅适用于一个视图,我无法使用一种将操作栏在整个应用程序中向下移动的解决方案。我只需要它在这个特定的视图中向下移动。

谢谢!

编辑: @布莱恩, 感谢您的建议,几乎完成了整个混乱。我正在尝试在皮肤内创建一个函数来添加 adMob 广告的空间。但是,我认为我没有正确引用该函数,因为当我这样做时,我没有收到任何错误,并且什么也没有发生。

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" >
    <!-- host component -->
    <fx:Metadata>
        [HostComponent("spark.components.ViewNavigator")]
    </fx:Metadata>
    <fx:Script>
        <![CDATA[

            public function adMobVisible(trueOrFalse:Boolean):void
            {
                if(trueOrFalse)
            {
                main_group.top=70;
            }
            else
            {
                main_group.top=0;
            }
            }

        ]]>
    </fx:Script>

    <!-- states -->
    <s:states>
        <s:State name="landscapeAndOverlay" />
        <s:State name="portraitAndOverlay" />
        <s:State name="landscape" />
        <s:State name="portrait" />
        <s:State name="disabled" />
        <s:State name="normal" />
        <!-- <s:State name="admob" /> -->
    </s:states>

    <s:VGroup id="main_group" width="100%" height="100%">
        <s:ActionBar id="actionBar" width="100%" />
        <s:Group id="contentGroup" width="100%" height="100%" />
    </s:VGroup>
</s:Skin>

我做了:

import skins.AdMobHolderSkin;

protected var ad:AdMobHolderSkin = new AdMobHolderSkin();

在上面......然后我只是尝试做一件简单的事情,例如:

ad.adMobVisible(true);

但什么也没有发生。有什么想法吗?感谢您对此提供帮助。

I'm trying to simply move the actionBar down 75 pixels so I can squeeze an adMob ad in there.

I tried:

navigator.actionBar.y=75;

But, i'm not seeing anything different visually, it's not moving, it's giving me no errors, but if i do trace(navigator.actionBar.y); it claims it's at 75....even though it's clearly not on the screen.

Does anyone have any ideas? Also, this would only be for ONE view, I can't use a solution that would move the action bar down throughout the entire application. I just need it moved down in THIS particular view.

Thanks!

EDIT:
@Brian,
Thanks for the suggestion, almost done this whole mess. I'm trying to make a function inside the skin to add the space for the adMob ad. But, I don't think im referencing the function correctly, because when i do it im not getting any errors, and nothing is happening.

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" >
    <!-- host component -->
    <fx:Metadata>
        [HostComponent("spark.components.ViewNavigator")]
    </fx:Metadata>
    <fx:Script>
        <![CDATA[

            public function adMobVisible(trueOrFalse:Boolean):void
            {
                if(trueOrFalse)
            {
                main_group.top=70;
            }
            else
            {
                main_group.top=0;
            }
            }

        ]]>
    </fx:Script>

    <!-- states -->
    <s:states>
        <s:State name="landscapeAndOverlay" />
        <s:State name="portraitAndOverlay" />
        <s:State name="landscape" />
        <s:State name="portrait" />
        <s:State name="disabled" />
        <s:State name="normal" />
        <!-- <s:State name="admob" /> -->
    </s:states>

    <s:VGroup id="main_group" width="100%" height="100%">
        <s:ActionBar id="actionBar" width="100%" />
        <s:Group id="contentGroup" width="100%" height="100%" />
    </s:VGroup>
</s:Skin>

I did:

import skins.AdMobHolderSkin;

protected var ad:AdMobHolderSkin = new AdMobHolderSkin();

up top... then I just tried to do a simple thing like:

ad.adMobVisible(true);

But nothing happens. Any ideas? Thanks for helping with this.

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

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

发布评论

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

评论(1

九厘米的零° 2024-12-20 11:28:03

如果您检查 ViewNavigatorSkin 的代码,您会发现它使用简单的数学来布局其两个项目(ActionBarGroup)。换句话说,它没有使用布局容器,其中设置 topy 会产生任何效果。

相反,您需要设置 ViewNavigator 的外观。首先,定义皮肤(注意我如何在 VGroup 中设置 top="75"

VNSkin.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark">
    <!-- host component -->
    <fx:Metadata>
        [HostComponent("spark.components.ViewNavigator")]
    </fx:Metadata>

    <!-- states -->
    <s:states>
        <s:State name="landscapeAndOverlay" />
        <s:State name="portraitAndOverlay" />
        <s:State name="landscape" />
        <s:State name="portrait" />
        <s:State name="disabled" />
        <s:State name="normal" />
        <s:State name="moved" />
    </s:states>

    <s:VGroup width="100%" height="100%" top="0" top.moved="75">
        <s:ActionBar id="actionBar" width="100%" />
        <s:Group id="contentGroup" width="100%" height="100%" />
    </s:VGroup>
</s:Skin>

然后,在我的 main 内部应用程序中,我将设置 ViewNavigator 的外观以使用此外观:

MyApp.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                            xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.ActionbarMoveHomeView" applicationDPI="160" >  
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        s|ViewNavigator {
            skinClass: ClassReference("VNSkin")
        }   
    </fx:Style>
</s:ViewNavigatorApplication>

最后,在我的视图中,我需要设置状态并将其在视图激活和停用时放回:

MyView .mxml

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:viewActivate>
        navigator.skin.currentState = "moved";
    </s:viewActivate>

    <s:viewDeactivate>
        navigator.skin.currentState = "normal";
    </s:viewDeactivate>

    <s:Label text="test" click="navigator.pushView(SecondPage)" />
</s:View>

注意这种技术会增加一些开销,因为您的 ViewNavigator 皮肤现在是 MXML 而不是纯 ActionScript 您可能会考虑基于 ViewNavigatorSkin 源代码在纯 ActionScript 中创建皮肤,这样您就可以。 巨大影响,我不会担心它。

可以将其与您的偏移量一起放置...但如果您没有注意到 MXML 皮肤对性能的
在写完答案后,我注意到您只想将其用于一个视图。我进行了修改,向 VNSkin 类添加一个状态,然后在视图代码中切换状态(viewActivateviewDeactivate。对于记录,这一切感觉就像是一种黑客攻击,我会考虑某种通知机制,以便您可以与皮肤进行通信,以便以除此之外的方式进行更改......但我至少让您走上了一条道路。我很乐意看到有人来这里。并提出更好的建议,直到那时,你就有了可行的方法:P

If you inspect the code for ViewNavigatorSkin, you will find that it lays out its two items (ActionBar and Group) using simple math. In other words, it is not using a layout container in which setting top or y will have any effect.

Instead, you need to skin the ViewNavigator. First, define the skin (notice how I set the top="75" in the VGroup :

VNSkin.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark">
    <!-- host component -->
    <fx:Metadata>
        [HostComponent("spark.components.ViewNavigator")]
    </fx:Metadata>

    <!-- states -->
    <s:states>
        <s:State name="landscapeAndOverlay" />
        <s:State name="portraitAndOverlay" />
        <s:State name="landscape" />
        <s:State name="portrait" />
        <s:State name="disabled" />
        <s:State name="normal" />
        <s:State name="moved" />
    </s:states>

    <s:VGroup width="100%" height="100%" top="0" top.moved="75">
        <s:ActionBar id="actionBar" width="100%" />
        <s:Group id="contentGroup" width="100%" height="100%" />
    </s:VGroup>
</s:Skin>

Then, inside of my main application, I will skin the ViewNavigator to use this skin:

MyApp.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                            xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.ActionbarMoveHomeView" applicationDPI="160" >  
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        s|ViewNavigator {
            skinClass: ClassReference("VNSkin")
        }   
    </fx:Style>
</s:ViewNavigatorApplication>

Finally, in my view, I need to set the state and put it back when the view is activated and deactivated:

MyView.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:viewActivate>
        navigator.skin.currentState = "moved";
    </s:viewActivate>

    <s:viewDeactivate>
        navigator.skin.currentState = "normal";
    </s:viewDeactivate>

    <s:Label text="test" click="navigator.pushView(SecondPage)" />
</s:View>

Note that this technique adds some overhead because your ViewNavigator skin is now MXML instead of pure ActionScript. You might consider creating a skin in pure ActionScript based off the ViewNavigatorSkin source code such that you can place it with your offset... but if you aren't noticing a huge performance hit from the MXML skin, I wouldn't worry about it.

EDIT
I noticed after I wrote my answer that you only want it for one view. I have made a modification to add a state to the VNSkin class and then switch the states in the view code (viewActivate and viewDeactivate. For the record, this all feels like a hack. I'd consider some sort of notification mechanism so that you can communicate to the skin in order to change in a way other than this... but I have at least put you on a path to doing this with one technique. I'd love to see someone come here and suggest something better. Until then, you have something that works :P

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