1

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

我试过了:

navigator.actionBar.y=75;

但是,我在视觉上没有看到任何不同,它没有移动,它没有给我任何错误,但如果我这样做trace(navigator.actionBar.y);,它声称它是 75 ......即使它显然不在屏幕上。

有没有人有任何想法?此外,这仅适用于 ONE 视图,我不能使用将操作栏向下移动到整个应用程序的解决方案。我只需要它在这个特定的视图中向下移动。

谢谢!

编辑:@Brian,谢谢你的建议,几乎把这整个搞砸了。我正在尝试在皮肤内创建一个功能来为 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);

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

4

1 回答 1

2

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

于 2011-11-02T20:16:35.573 回答